开发者

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

开发者 https://www.devze.com 2023-03-28 04:56 出处:网络
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? I use Ubuntu, and I\'ve found the easiest way to install newer ver

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?


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:~$ 


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 "*******************"


1 Install RVM:

https://rvm.io

2 Then install Ruby 1.9.2

rvm install 1.9.2


Since the original question was about the latest version, here is how to get Ruby 2.2.

apt-add-repository ppa:brightbox/ruby-ng
apt-get update
apt-get install ruby2.2

Here is how to get Ruby 2.3.

apt-get install ruby2.3 ruby2.3-dev

Info on brightbox's maintainance of these.


Using sudo apt-get install ruby-full you will get old version of ruby (1.9) currently existing in Ubuntu repos. You might want to check installation from source

Download ruby tar from here and then run:

$ tar -xf ruby-X.X.X.tar.gz
$ cd ruby-X.X.X
$ ./configure
$ make
$ sudo make install

In some cases you will need to realod bash by typing:

$ bash


It depends on what Ubuntu version you are running, you can get the ruby packages with this link http://packages.ubuntu.com/search?keywords=ruby1.9.1&searchon=names&suite=all&section=all, to get the latest Ruby(1.9.2-p290) installed, you have to upgrade your Ubuntu to oneiric, if you don't like to upgrade your system, maybe you have to install Ruby with RVM as fl00r answered.


I might came late but this is a very useful website that provides Ubuntu packages and it seems to be maintained and up-to-date. Look here.


You should check stackoverflow more carefully before asking questions.

Installing Ruby 1.9.1 on Ubuntu?

sudo apt-get install ruby1.9.1-full
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号