Friday, March 7, 2014

Migrate from RVM to Rbenv and install Ruby on Rails in Ubuntu Saucy 13.10

This blog post shows how to migrate from RVM to Rbenv, then install the latest Ruby on Rails version. (By the time of writing, it was Ruby 2.1.1 and Rails 4.1.0.rc1...)

Removing RVM

$ rvm implode
Are you SURE you wish for rvm to implode?
This will recursively remove /home/joseph/.rvm and other rvm traces?
(anything other than 'yes' will cancel) > yes
Removing rvm-shipped binaries (rvm-prompt, rvm, rvm-sudo rvm-shell and rvm-auto-ruby)
Removing rvm wrappers in /home/joseph/.rvm/bin
Hai! Removing /home/joseph/.rvm
/home/joseph/.rvm has been removed.

Note you may need to manually remove /etc/rvmrc and ~/.rvmrc if they exist still.
Please check all .bashrc .bash_profile .profile and .zshrc for RVM source lines and delete or comment out if this was a Per-User installation.
Also make sure to remove `rvm` group if this was a system installation.
Finally it might help to relogin / restart if you want to have fresh environment (like for installing RVM again).


If you cancel it, you will receive the following message:

Psychologist intervened, cancelling implosion, crisis avoided :)

After that, please remove this line in bash profile:

PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting

For Ubuntu 13.10, the bash profile is saved in the .bashrc file, you can open it using any text editor:

$ nano ~/.bashrc


Installing Rbenv

Make sure you have all the dependencies ready. If not, make sure you install using

$ sudo 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 libgdbm-dev ncurses-dev automake libtool bison subversion pkg-config libffi-dev

(Some of these may not be needed... correct me if I am wrong)

Then, download a copy of the rbenv official repository by running 'git clone' command:

$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv

Steps to install:

$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
$ echo 'eval "$(rbenv init -)"' >> ~/.bashrc

Then, download the ruby-build repository into your machine into ~/.rbenv/plugins folder.

~/.rbenv/plugins$ git clone git://github.com/sstephenson/ruby-build.git
Cloning into 'ruby-build'...
remote: Reusing existing pack: 3077, done.
remote: Total 3077 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3077/3077), 510.82 KiB | 286.00 KiB/s, done.
Resolving deltas: 100% (1404/1404), done.
Checking connectivity... done
~/.rbenv/plugins$

Now it works!

$ rbenv
rbenv 0.4.0-89-g14bc162
Usage: rbenv <command> [<args>]

Some useful rbenv commands are:
   commands    List all available rbenv commands
   local       Set or show the local application-specific Ruby version
   global      Set or show the global Ruby version
   shell       Set or show the shell-specific Ruby version
   install     Install a Ruby version using ruby-build
   uninstall   Uninstall a specific Ruby version
   rehash      Rehash rbenv shims (run this after installing executables)
   version     Show the current Ruby version and its origin
   versions    List all Ruby versions available to rbenv
   which       Display the full path to an executable
   whence      List all Ruby versions that contain the given executable

See `rbenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/sstephenson/rbenv#readme

If it is not working on your Ubuntu machine, you may need to restart terminal without login shell (which works with RVM). Then, you should be able to run 'rbenv' command.

Install Ruby

$ rbenv install 2.1.1
Downloading ruby-2.1.1.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/e57fdbb8ed56e70c43f39c79da1654b2
Installing ruby-2.1.1...
Installed ruby-2.1.1 to /home/joseph/.rbenv/versions/2.1.1

$

If you can't run 'rbenv install', you may need to install it using './install.sh' in ruby-build folder.

To set the Ruby version newly installed as global.

$ rbenv global 2.1.1
$ rbenv rehash

Restart your terminal (or open a new one :p)

$ ruby -v
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-linux]
$

Now it works!

If you have local version of Ruby installed, it may show the local Ruby version after rehash.

Install Rails

$ gem install rails -v 4.1.0.rc1 --no-ri --no-rdoc
Fetching: atomic-1.1.15.gem (100%)
Building native extensions.  This could take a while...
Successfully installed atomic-1.1.15
Fetching: thread_safe-0.2.0.gem (100%)
Successfully installed thread_safe-0.2.0
Fetching: minitest-5.3.0.gem (100%)
Successfully installed minitest-5.3.0
Fetching: tzinfo-1.1.0.gem (100%)
Successfully installed tzinfo-1.1.0
Fetching: i18n-0.6.9.gem (100%)
Successfully installed i18n-0.6.9
Fetching: activesupport-4.1.0.rc1.gem (100%)
Successfully installed activesupport-4.1.0.rc1
Fetching: erubis-2.7.0.gem (100%)
Successfully installed erubis-2.7.0
Fetching: builder-3.2.2.gem (100%)
Successfully installed builder-3.2.2
Fetching: actionview-4.1.0.rc1.gem (100%)
Successfully installed actionview-4.1.0.rc1
Fetching: rack-1.5.2.gem (100%)
Successfully installed rack-1.5.2
Fetching: rack-test-0.6.2.gem (100%)
Successfully installed rack-test-0.6.2
Fetching: actionpack-4.1.0.rc1.gem (100%)
Successfully installed actionpack-4.1.0.rc1
Fetching: activemodel-4.1.0.rc1.gem (100%)
Successfully installed activemodel-4.1.0.rc1
Fetching: arel-5.0.0.gem (100%)
Successfully installed arel-5.0.0
Fetching: activerecord-4.1.0.rc1.gem (100%)
Successfully installed activerecord-4.1.0.rc1
Fetching: mime-types-1.25.1.gem (100%)
Successfully installed mime-types-1.25.1
Fetching: polyglot-0.3.4.gem (100%)
Successfully installed polyglot-0.3.4
Fetching: treetop-1.4.15.gem (100%)
Successfully installed treetop-1.4.15
Fetching: mail-2.5.4.gem (100%)
Successfully installed mail-2.5.4
Fetching: actionmailer-4.1.0.rc1.gem (100%)
Successfully installed actionmailer-4.1.0.rc1
Fetching: thor-0.18.1.gem (100%)
Successfully installed thor-0.18.1
Fetching: railties-4.1.0.rc1.gem (100%)
Successfully installed railties-4.1.0.rc1
Fetching: bundler-1.6.0.rc.gem (100%)
Successfully installed bundler-1.6.0.rc
Fetching: tilt-1.4.1.gem (100%)
Successfully installed tilt-1.4.1
Fetching: multi_json-1.8.4.gem (100%)
Successfully installed multi_json-1.8.4
Fetching: hike-1.2.3.gem (100%)
Successfully installed hike-1.2.3
Fetching: sprockets-2.11.0.gem (100%)
Successfully installed sprockets-2.11.0
Fetching: sprockets-rails-2.0.1.gem (100%)
Successfully installed sprockets-rails-2.0.1
Fetching: rails-4.1.0.rc1.gem (100%)
Successfully installed rails-4.1.0.rc1
29 gems installed
$

Note: if you don't install Rails with --no-ri --no-rdoc options, you may face the following conflicts:

rdoc's executable "rdoc" conflicts with /home/joseph/.rbenv/versions/2.1.1/bin/rdoc
Overwrite the executable? [yN]  y
rdoc's executable "ri" conflicts with /home/joseph/.rbenv/versions/2.1.1/bin/ri
Overwrite the executable? [yN]  y
Depending on your version of ruby, you may need to install ruby rdoc/ri data:

<= 1.8.6 : unsupported
 = 1.8.7 : gem install rdoc-data; rdoc-data --install
 = 1.9.1 : gem install rdoc-data; rdoc-data --install
>= 1.9.2 : nothing to do! Yay!

I will just overwrite it.

Well done! Now you have migrated from RVM to rbenv, and have Ruby 2.1.1 and Rails 4.1.0.rc1 installed!

Thank you for reading! :D


No comments:

Post a Comment