Wednesday, September 12, 2012

Install Rails on Ubuntu 12.04 with RVM support

Nowadays, RVM is very popular in Ruby/Rails community on Linux/OS X. Even more, it's best practice to use RVM for Ruby environment management. Ubuntu is my major Linux distribution. Here I've collected steps for installing Ruby, Rails via RVM on Ubuntu 12.04. I must admit that in many cases it's the re-post from different sources.

So, let's start.

Install Ruby, Rails (see the source):
sudo apt-get update
sudo apt-get install curl
curl -L get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
rvm requirements
rvmsudo apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion
rvm install 1.9.3
rvm use 1.9.3 --default
rvm rubygems current
gem install rails
Please check the original in case you have some issues during this process.

Fix Bundler issues:
If you create Rails project or any other Ruby project which supports Bundler and run install command, you will get the next error:
$ bundle install
...
ERRRO: Gem bundler is not installed, run `gem install bundler` first.

But gem list clearly shows us that bundler has been properly installed. To fix this problem We have to tweak .bashrc file a little (see the original idea):
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bashrc
source ~/.bashrc

Fix rails server throw could not find JavaScript runtime
Now you will get the next interesting error when you tried to run rails server:
username@ubuntu:~/_Projects/Rails/blog$ rails server
/home/username/.rvm/gems/ruby-1.9.3-p194/gems/execjs-1.4.0/lib/execjs/runtimes.rb:51:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
 from /home/username/.rvm/gems/ruby-1.9.3-p194/gems/execjs-1.4.0/lib/execjs.rb:5:in `'
 from /home/username/.rvm/gems/ruby-1.9.3-p194/gems/execjs-1.4.0/lib/execjs.rb:4:in `'
 from /home/username/.rvm/gems/ruby-1.9.3-p194/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `require'
 from /home/username/.rvm/gems/ruby-1.9.3-p194/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `'
 from /home/username/.rvm/gems/ruby-1.9.3-p194/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `require'
 from /home/username/.rvm/gems/ruby-1.9.3-p194/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `'
 from /home/username/.rvm/gems/ruby-1.9.3-p194/gems/coffee-rails-3.2.2/lib/coffee-rails.rb:1:in `require'
 from /home/username/.rvm/gems/ruby-1.9.3-p194/gems/coffee-rails-3.2.2/lib/coffee-rails.rb:1:in `'
 from /home/username/.rvm/gems/ruby-1.9.3-p194/gems/bundler-1.2.0/lib/bundler/runtime.rb:68:in `require'
 from /home/username/.rvm/gems/ruby-1.9.3-p194/gems/bundler-1.2.0/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
 from /home/username/.rvm/gems/ruby-1.9.3-p194/gems/bundler-1.2.0/lib/bundler/runtime.rb:66:in `each'
 from /home/username/.rvm/gems/ruby-1.9.3-p194/gems/bundler-1.2.0/lib/bundler/runtime.rb:66:in `block in require'
 from /home/username/.rvm/gems/ruby-1.9.3-p194/gems/bundler-1.2.0/lib/bundler/runtime.rb:55:in `each'
 from /home/username/.rvm/gems/ruby-1.9.3-p194/gems/bundler-1.2.0/lib/bundler/runtime.rb:55:in `require'
 from /home/username/.rvm/gems/ruby-1.9.3-p194/gems/bundler-1.2.0/lib/bundler.rb:128:in `require'
 from /home/username/_Projects/Rails/blog/config/application.rb:7:in `'
 from /home/username/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands.rb:53:in `require'
 from /home/username/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands.rb:53:in `block in '
 from /home/username/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands.rb:50:in `tap'
 from /home/username/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands.rb:50:in `'
 from script/rails:6:in `require'
 from script/rails:6:in `
'
Install Node.js to fix this error:
$ sudo apt-get install nodejs
Check this wiki "Installing Node.js via package manager" If you have some troubles with installing node.js


Links:

No comments:

Post a Comment