FreeBSD from a scratch for Rails

I had to prepare short information how to setup FreeBSD server to get Rails up and running. Not for production purposes but for development. Having it written down I decided to share with this. Here goes little howto (more on the way!):

First You need FreeBSD. Fortunately we have virtualization nowadays! So I recommend You get VMWare Player and search for system images with FreeBSD pre-installed to download. Like those.

So You have downloaded and installed software. Now we can start with configuration. Whole process can take up to few hours depending on internet connection speed and CPU computing power. But most of time it can be left unattended so You can work on other things in this time.

So let’s start!


Login as root and bring networking up:

dhclient lnc0
ifconfig lnc0

Write down IP address which was assigned to lnc0 interface. We will need this later. Now change root’s password (passwd) and issue command sysinstall. It will bring curses-based FreeBSD configuration application. It has a little weird user interface, but You need to get used to it.

Choose menu Configuration, Networking and check SSHD for start. Next go to Configuration, Interface, lnc0. You don’t need IPv6 and do want to use DHCP. In next screen type some hostname for this virtual machine.

Now we add user with adduser. Choose some login and You can accept defaults, except one. When You will be asked:

Login group is XYZ. Invite XYZ into other groups?

Answer typing in wheel. If You omit this You, won’t be able to make su root when logged as this user.

Reboot virtual machine (reboot) to make sure You did setup network correctly.

Now grab Your favorite SSH client (probably it is Putty) and connect to virtual machine (using IP address You have written down earlier). Now things are easier (copy&paste).

First:

#change role to superuser
su -
#if You are behind proxy set environment 
#I have not tested it since I don't have proxy here ;)
setenv http_proxy "http://PROXY_IP_ADDRESS:port"

#get package to update ports subsystem
fetch ftp://ftp.freebsd.org/pub/FreeBSD/releases/i386/6.2-RELEASE/packages/All/cvsup-without-gui-16.1h_2.tbz
pkg_add cvsup-without-gui-16.1h_2.tbz

Now we have tool to get current ports (aka applications collection). Url to fetch cvsup could be void in future. First there could be new version of cvsup so You need change package name. Second – when next FreeBSD releases will be available 6.2 release will be moved to ftp archive. Anyway – when fetch could not locate file use Your web browser to find proper location and use it.

# chsh (default root shell) does need to 
# refresh path to find new commands
rehash

#refresh ports
cd /usr/ports
fetch http://nhw.pl/download/SUP
cvsup SUP
make fetchindex

I have prepared cvsup configuration file it should work also in future. If You can not connect to cvsup server edit downloaded file and change cvsup host to other. You can use some root servers cvsupX.freebsd.org or national like cvsupX.DD.freebsd.org replacing X through some number or omitting number completely, and DD replace with some TLD doamin (like uk, pl, de). Of course different countries have different numbers of cvsup servers.

Now we install a smarter port management tool (written in Ruby – in FreeBSD this language was in use long time before Rails!):

#install 'smarter' ports manager
cd ports-mgmt/portupgrade
make install clean
rehash

#install sqlite (for dead simple SQL configuration for Rails)
portinstall sqlite3

Now we can install RubyGems. I recommend You to install it by hand, leaving ports version not touched. Gems have built-in fabulous update mechanisms so IMO it is better to relay on them – it will be easier to You to operate later in Linux for example.

cd

#install RubyGems
fetch http://rubyforge.org/frs/download.php/29548/rubygems-1.0.1.tgz
tar -xzf rubygems-1.0.1.tgz
cd rubygems-1.0.1
ruby setup.rb

#clean up
cd ..
rm -fR rubygems*

#got nice gem command
ln -s /usr/local/bin/gem18 /usr/local/bin/gem
rehash

#now we can start installing gems
gem update --system

gem install sqlite3-ruby
gem install rake
gem install rails

#install addons like bash (or other shell You like) and text editor
portinstall bash vim-lite

rehash

#change default shell, store bash location
which bash

#change shell path to path to bash 
chsh

Now You have basic system to start working on Your first Rails application (or to be step away from checking some other cool frameworks like Merb).

Join the Conversation

2 Comments

  1. Accualy most convinient way to get ports is issuing following command: portsnap fetch extract (portsnap is buildin in >=6.2-RELEASE versions, for others it can be added via pkg_add -vr portsnap).

    And easier way to configure lnc0 interface as dhcp is: echo ifconfig_lnc0=\”DHCP\” >> /etc/rc.conf

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.