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

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

Related

Installing Ruby on Linux

I want to install only Ruby, not Ruby on Rails, I check this command:
sudo apt-get install ruby-full -g
But the terminal report me this error:
E:Command line option 'g' [from -g] is not known
This command will install the latest stable Ruby version and will make it
available globally (through the '-g' parameter) on your system environment...
Why do I get this error?
Update your package manager first:
sudo apt-get update
This must finish without error or the following step will fail.
Install curl:
sudo apt-get install curl
You’ll use curl for installing RVM.
Install RVM
curl -L https://get.rvm.io | bash -s stable --ruby
You Already Have RVM Installed
If you already have RVM installed, update it to the latest version and install Ruby:
rvm get stable --autolibs=enable
Install Ruby:
rvm install ruby
apt-get install ruby-full
apt (Debian or Ubuntu)
Debian GNU / Linux and Ubuntu use the apt package manager. You can use it as follows:
font: https://www.ruby-lang.org/pt/documentation/installation/
-g is not an option of apt-get. There is nothing like "global" install in apt-get. Everything is installed globally. If you want to install the ruby-full package, just do
sudo apt-get install ruby-full
Another option is to install ruby via rvm.io or rbenv

RVM installed but not working?

I installed RVM on my Fedora 19 system a few months ago, and it was working fine. Then I had some other work and when I opened the machine again, it said:
# rvm
bash: rvm: command not found...
I tried to reinstall RVM, and this is what I get:
# rpm -i rvm-devel-1.17-8.fc19.x86_64.rpm
package rvm-devel-1.17-8.fc19.x86_64 is already installed
But I can't find it.
# ps ax | grep rvm
14363 pts/0 S+ 0:00 grep --color=auto rvm
Can anyone help me? What exactly is the problem?
P.S: The package rvm is there on the system.
# rpm -q rvm
rvm-1.17-8.fc19.x86_64
I recommend you to reinstall RVM, maybe it's crashed due to some event.
Use this command to implode it:
rvm implode
Or:
rm -rf ~/.rvm
Then install it by running:
sudo apt-get install curl
curl -L get.rvm.io | bash -s stable --auto
Then you'll need to reload the ~/.bash_profile file which you can do with this small command:
. ~/.bash_profile
Make sure to install other packages needed for Ruby to work:
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 ncurses-dev automake libtool bison subversion pkg-config
sudo apt-get install pkgconfig
Now install the latest Ruby:
rvm install 2.0.0
rvm use 2.0.0
ruby -v
Now you can install Rails:
gem install rails -v 4.0.0
the package rvm-devel-1.17-8.fc19.x86_64 is not rvm as per http://rpm.pbone.net/index.php3/stat/4/idpl/20537074/dir/fedora_19/com/rvm-devel-1.17-8.fc19.x86_64.rpm.html it is:
The rvm-devel package contains libraries and header files for
developing applications that use rvm.
Follow installation instructions http://rvm.io/rvm/install to get RVM installed, make sure to read the outputs as important hints might be printed for you.
to uninstall rvm use anyone of the following:
rvm implode
or
rm -rf ~/.rvm
Just to be sure restart the terminal before you try installing rvm again

Installing Compass & Susy on Ubuntu 12.04

I'm trying to install Compass and Susy on my Ubuntu 12.04.
What I have tried are the following steps on the console:
sudo apt-get install rubygems1.8
sudo gem install rubygems-update # Instead of sudo gem update --system
sudo update_rubygems
sudo gem install compass # Installing Compass & Sass
sudo gem install susy
So the gems are installed and will be listed when I do the following command:
gem list
But now, when I try to create a new compass project with
compass create project
I get the following error:
/usr/local/bin/compass: /usr/bin/ruby1.9.1: bad interpreter: No such file or directory
My current ruby version is 1.8.7. So I installed ruby 1.9.1 and get it working.
The console still says the current ruby version is 1.8.7
My question: Do I have to run with both ruby versions to get that working? Is there another way under ubuntu? It's working, I know, but it's a bit confusing.
Using Ubuntu's package manager for multiple ruby versions is a bit of a lost cause.
Most people use rvm, which allows you to install and switch between multiple rubies very easily.
Other popular options are rbenv and chruby. It's just a question of personal preference, but I'd say that rvm has the slight edge for beginners.
Also, I wouldn't recommend installing ruby 1.9.1 - it's best to use 1.9.3 as there are some compatibility issues with other 1.9.x versions.
You can then install compass and sass via ruby gems (rather than aptitude):
$ gem install compass
$ gem install sass
This simple command works on ubuntu 14.10
sudo apt-get install ruby-compass
RVM is awesome and really easy to install. I managed to install rvm, compass, and sass with these commands in my terminal:
Firstly:
curl -L https://get.rvm.io | bash -s stable --rails --autolibs=enabled --ruby=1.9.3
This will instal rvm, it will put a command in ~/.bash_profile to load rvm automatically, except this isn't what Ubuntu uses so put this line into your ~/.bashrc file:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
Then simply run:
gem install compass
gem install susy #(or sass)
Install build-essentials and ruby-dev packages to install compass without errors.
sudo apt-get install build-essential
sudo apt-get install ruby
sudo apt-get install ruby-dev
sudo gem install compass
Masterchief's answer is close, but didn't work for me. This web page provided a clear and reliably working way to install rvm on my ubuntu server instance: http://ryanbigg.com/2010/12/ubuntu-ruby-rvm-rails-and-you/

Installing Ruby via rbenv fails

Problem: I installed ruby, but it is not recognized correctly.
I'm following the deploying to VPS: https://github.com/railscasts/335-deploying-to-a-vps
I am setting my server on ubuntu 12.04 LTS to deploy my rails app. I'm following the railscast on deploying to a VPS, and trying to install ruby through rbenv. It seemed everything was installed correctly, but when I tried to check the ruby version, it gave me errors. The following are the commands that I ran.
deployer#max:~$ rbenv install 1.9.3-p125
Downloading yaml-0.1.4.tar.gz...
-> http://cloud.github.com/downloads/sstephenson/ruby-build-download-mirror/36c852831d02cf90508c29852361d01b
Installing yaml-0.1.4...
Installed yaml-0.1.4 to /home/deployer/.rbenv/versions/1.9.3-p125
Downloading ruby-1.9.3-p125.tar.gz...
-> http://cloud.github.com/downloads/sstephenson/ruby-build-download-mirror/e3ea86b9d3fc2d3ec867f66969ae3b92
Installing ruby-1.9.3-p125...
Installed ruby-1.9.3-p125 to /home/deployer/.rbenv/versions/1.9.3-p125
Downloading rubygems-1.8.23.tar.gz...
-> http://cloud.github.com/downloads/sstephenson/ruby-build-download-mirror/178b0ebae78dbb46963c51ad29bb6bd9
Installing rubygems-1.8.23...
Installed rubygems-1.8.23 to /home/deployer/.rbenv/versions/1.9.3-p125
deployer#max:~$ rbenv global 1.9.3-p125
deployer#max:~$ ruby -v
'ruby' program can be found in the following packages:
* ruby1.8
* ruby1.9.1
How do I solve this?
You don't need to use rbenv to install a specific version of Ruby. Instead use ruby-build to install 1.9.3-p125 into /usr/local:
ruby-build 1.9.3-p125 /usr/local/
Or, install Ruby manually:
# Compile Ruby (instead of rbenv)
sudo apt-get -y install build-essential zlib1g-dev libssl-dev libreadline5-dev libyaml-dev
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p125.tar.gz
tar -xvzf ruby-1.9.3-p125.tar.gz
cd ruby-1.9.3-p125/
./configure --prefix=/usr/local
make
sudo make install
sudo gem install bundler --no-ri --no-rdoc
Maybe you are missing
eval "$(rbenv init -)";
in your shell config
You should restart the shell to allow rbenv to find the new Ruby
$ exec $SHELL
$ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [i686-linux]

cannot load such file -- zlib even after using rvm pkg install zlib

I installed zlib package and ruby 1.9.3 using rvm, but whenever I try to install
gems it says
cannot load such file -- zlib
The commands I used to install are
$ rvm install 1.9.3
$ rvm pkg install zlib
$ rvm reinstall 1.9.3 --with-readline-dir=/home/username/.rvm/usr \
--with-iconv-dir=/home/username/.rvm/usr \
--with-zlib-dir=/home/username/.rvm/usr \
--with-openssl-dir=/home/username/.rvm/usr
$ rvm use 1.9.3
$ gem install heroku
ERROR: Loading command: install (LoadError)
cannot load such file -- zlib
ERROR: While executing gem ... (NameError)
uninitialized constant Gem::Commands::InstallCommand
All the help on this subject tells me to just do rvm pkg install zlib, and
then reinstall the ruby with --with-zlib-dir=/home/username/.rvm/usr, but this
didn't work.
I ended up installing zlib from apt-get and then reinstalling ruby to not use the rvm directory for zlib.
Here's how do:
$ sudo apt-get install zlib1g-dev
$ rvm reinstall 1.9.3
[Edit] As commenter #chrisfinne mentions, on CentOS/RedHat based systems:
$ sudo yum install zlib-devel
$ rvm reinstall 1.9.3
The both other responses were almost right...
The rvm site for zlib provides a quick fix!
On the top off the page is a "Quick fix" follow it's instructions, it will:
fix your installation,
provide you instructions what to do to install zlib from your system
and show how to reinstall ruby
Use autolibs to install dependencies:
rvm autolibs enable
rvm reinstall 1.9.3
RVM will automatically install missing dependencies and use them for compiling ruby.
More details on autolibs => http://rvm.io/rvm/autolibs
The solution that worked for me is described in rvm github repo, issue #3389.
Run
rvm install 2.3.0 --with-zlib-dir=/usr/local/Cellar/zlib/1.2.8
for ruby 2.3.0 version.
Ruby has a bunch of package dependencies like the one on zlib-devel. They're nasty because there's nothing to indicate you need the library until get some obscure error message while trying to do something routine.
The solution is to use rvm. Use it even if you only need one version of ruby. Why? Because then you can do
rvm requirements
This will probe your particular OS and produce a set of commands you can copy back to the command line to install those missing packages.
rvm pkg install openssl && rvm pkg install zlib && rvm pkg install libyaml &&
rvm pkg install iconv
rvm install 1.9.3-p0 --with-opt-dir=$HOME/.rvm/usr \
--with-libxml2-dir=/usr/local/Cellar/libxml2/2.7.8 \
--with-readline-dir=/usr/local/Cellar/readline/6.2.1

Resources