Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I install the latest version of ruby in Ubuntu?

Tags:

ruby

ubuntu

I currently have ruby version 1.8.2 in my machine and I would like to upgrade it to 1.9.2. How am i supposed to do it?

like image 788
Rahul Avatar asked Aug 14 '11 14:08

Rahul


People also ask

How do I get Ruby on Ubuntu?

Installing Ruby from Ubuntu Repositories The easiest way to install Ruby on Ubuntu is by using the apt package manager. At the time of writing, the version in the Ubuntu repositories is 2.7. 0 , which may not always be the latest stable release. Your Ruby version may differ from the one shown above.


2 Answers

I use Ubuntu, and I've found the easiest way to install newer versions of Ruby is to use rvm.

The instructions are here: https://rvm.io/rvm/install/

Basically, it installs different versions of Ruby locally for the user and updates environment variables for Ruby and gems based on which version you decide to use.

It's this easy:

jim@schubert:~$ rvm use system
Now using system ruby.
jim@schubert:~$ ruby -v
ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux]
jim@schubert:~$ gem -v
1.3.7
jim@schubert:~$ rvm use 1.9.2
Using /home/jim/.rvm/gems/ruby-1.9.2-p180
jim@schubert:~$ ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]
jim@schubert:~$ gem -v
1.5.2
jim@schubert:~$ 
like image 182
Jim Schubert Avatar answered Sep 20 '22 21:09

Jim Schubert


I don't like having RVM on production server, so I usually install ruby from source with an install script like this:

#!/bin/bash

tmp_dir="/tmp"
version="2.2.3"
minor_version="2.2"
ruby_version="ruby-$version"

echo "*******************"
echo "* Installing Ruby *"
echo "*******************"

sudo apt-get install -y autoconf build-essential libreadline-dev libssl-dev libyaml-dev zlib1g-dev libffi-dev

mkdir -p "$tmp_dir"
cd "$tmp_dir"

wget "http://cache.ruby-lang.org/pub/ruby/$minor_version/$ruby_version.tar.gz"
tar -xvzf $ruby_version.tar.gz
cd $ruby_version

./configure --disable-install-doc
make --jobs `nproc`
sudo make install

cd ..
rm $ruby_version.tar.gz
rm -rf $ruby_version

echo "*******************"
echo "* Ruby installed! *"
echo "*******************"
like image 22
Lasse Skindstad Ebert Avatar answered Sep 17 '22 21:09

Lasse Skindstad Ebert