Ruby on Rails installation
From Smith family
How to install Ruby, Gems, and Rails. Instructions for Linux workstation, Linux server, and Windows workstation.
Contents |
Installation on Ubuntu Linux
If MySQL isn't already installed, install and configure it.
- Install the following packages:
- Server
root@server:~# apt-get install ruby-full build-essential apache2 apache2-mpm-prefork \ apache2-prefork-dev libapache2-mod-ruby ruby-elisp libmysqlclient-dev libruby-extras \ libyaml-ruby libzlib-ruby libopenssl-ruby \ sqlite3 libmysql-ruby \ libmysql-ruby libsqlite3-ruby libsqlite3-dev imagemagick graphicsmagick libmagick10 libgraphicsmagick1 libgraphicsmagick1-dev librmagick-ruby
- Desktop
root@desktop:~# apt-get install ruby-full build-essential ruby-elisp libmysqlclient-dev \ libyaml-ruby libzlib-ruby libruby-extras libopenssl-ruby \ sqlite3 libmysql-ruby \ libmysql-ruby libsqlite3-ruby libsqlite3-dev \ imagemagick graphicsmagick libmagick10 libgraphicsmagick1 libgraphicsmagick1-dev librmagick-ruby
- (Optional) Installing Ruby 1.9.2 on Ubuntu, making a system-wide change with the
alternativessystem.- Install Ruby 1.9.2 (still in the 1.9.1 package)
root@desktop:~# apt-get install ruby1.9.1 ruby1.9.1-dev rubygems1.9.1 irb1.9.1 ri1.9.1 rdoc1.9.1 g++
- Bring Ruby into the
alternativessystem
- Bring Ruby into the
root@desktop:~# update-alternatives --install /usr/bin/ruby ruby /usr/bin/ruby1.8 500 \
--slave /usr/bin/ri ri /usr/bin/ri1.8 \
--slave /usr/bin/irb irb /usr/bin/irb1.8 \
--slave /usr/bin/rdoc rdoc /usr/bin/rdoc1.8
- Bring Ruby 1.9 into the
alternativessystem
- Bring Ruby 1.9 into the
root@desktop:~# update-alternatives --install /usr/bin/ruby ruby /usr/bin/ruby1.9.1 400 \
--slave /usr/bin/ri ri /usr/bin/ri1.9.1 \
--slave /usr/bin/irb irb /usr/bin/irb1.9.1 \
--slave /usr/bin/rdoc rdoc /usr/bin/rdoc1.9.1
- Choose which Ruby you want, system-wide
root@desktop:~# update-alternatives --config ruby
- and then choose Ruby 1.9.1 from the menu
- Check it works with
root@desktop:~# ruby --version
- (Instructions from Michal Frackowiak's blog)
- Or, if you want to install different versions on a per-user basis, or switch quickly between them, use RVM.
- Build
gemfrom source, to avoid it conflicting withapt
root@server:~# tar -xzf rubygems-1.2.0.tgz root@server:~# rm rubygems-1.2.0.tgz root@server:~# cd rubygems-1.2.0 root@server:~# ruby setup.rb root@server:~# cd .. root@server:~# rm -r rubygems-1.2.0 root@server:~# ln -s /usr/bin/gem1.8 /usr/bin/gem
- (Do not use
sudo ruby rubygemsx.x.x/setup.rb)
- Update
gem
root@server:~# gem update --system root@server:~# gem install rubygems-update root@server:~# update_rubygems
- (The first step is needed to upgrade to 1.2.0; the last two steps are needed for the upgrade to 1.3.1. It's best to do them both.)
- Install the required gems. On the server, install:
root@server:~# gem update root@server:~# gem install rails root@server:~# gem install mysql root@server:~# gem install sqlite3 root@server:~# gem install passenger root@server:~# gem install mongrel_cluster root@server:~# gem install bundler root@server:~# gem install jeweler
- On the development machine, install:
root@desktop:~# gem update root@desktop:~# gem install rails root@desktop:~# gem install mysql root@desktop:~# gem install sqlite3 root@desktop:~# gem install passenger root@desktop:~# gem install capistrano root@desktop:~# gem install rspec root@desktop:~# gem install cucumber root@desktop:~# gem install yard root@desktop:~# gem install termios root@desktop:~# gem install bundler root@desktop:~# gem install jeweler
RVM
If using RVM to keep different Ruby versions around, you need to install the Readline development headers first:
root@desktop:~# apt-get install libreadline-dev
user@desktop:~$ gem install rails rake rcov rspec gemcutter git jeweler capistrano mysql sqlite3 shoulda cucumber yard
- If any of the packages fail to install, simply re-install them and they should work fine.
- To install Phusion Passenger, give the command
root@desktop:~# gem install passenger root@desktop:~# passenger-install-apache2-module
- and follow the instructions. The script will compile and install a new Apache2 module for you.
- You'll need to add these lines to
/etc/apache2/httpd.conf
# Load the Passenger module for Rails applications LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.0.6/ext/apache2/mod_passenger.so PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.0.6 PassengerRuby /usr/bin/ruby1.8
Installing Rails with NetBeans 6.5 on Windows
- Download and install Netbeans 6.5
- Set the JAVA_HOME environment variable
- Right click the 'My Computer' icon on the desktop. Select 'Properties'
- Select the 'Advanced' tab, press the 'Environment variables' button
- Add a new System variable,
JAVA_HOME, which contains the path of the NetBeans JDK (currentlyC:\Program Files\Java\jdk1.6.0_03: use NetBeans's Tools | Java Platform menu item to find the path)
- (See here for pretty pictures)
- Update RubyGems
- Open a new command terminal (Start | Run | cmd)
- CD to C:\Program Files\NetBeans 6.5\ruby2\jruby-1.1.4\bin\
- Update RubyGems
gem install rubygems-update rubygems-update gem update --system gem --version
- Check you're at version 1.3.5
- Update Rails. Stay in the same directory and give the command
gem update
- Check Rails is at version 2.3.3
- Install the Ruby MySQL gem
gem install mysql
Getting NetBeans 6.5 to use another Ruby
We'll be using the system-wide Ruby and Gem programs, rather than NetBeans's built-in JRuby ones. To make NetBeans know where they are, use the Tools | Ruby Platforms menu item and tell NetBeans about the Ruby executable in /usr/bin/ruby and /usr/bin/gem. Do the same for Tools | Ruby gems.
Then tell NetBeans which Ruby platform to use. You need to do this on a project-by-project basis. Right-click on the project's root node in the NetBeans navigator, select the Set Configuration | Customize... option and select the right Ruby platform from the drop-down list at the top of the dialog.
Note that WEBrick runs NetBeans's 'main project' when a project is run.
When creating a new project, the database needs to be created. Either do this from the Instant Rails Ruby console, or use the NetBeans MySQL database connectors. (Does this latter approach work?)
