sudo apt-get install ruby1.9
should do the trick.
You can find what libraries are available to install by
apt-cache search <your search term>
So I just did apt-cache search ruby | grep 9 to find it.
You'll probably need to invoke the new Ruby as ruby1.9, because Ubuntu will probably default to 1.8 if you just type ruby.
sudo apt-get install ruby1.9
should do the trick.
You can find what libraries are available to install by
apt-cache search <your search term>
So I just did apt-cache search ruby | grep 9 to find it.
You'll probably need to invoke the new Ruby as ruby1.9, because Ubuntu will probably default to 1.8 if you just type ruby.
There's really no reason to remove ruby1-8, unless someone else knows better. Execute the commands below to install 1.9 and then link ruby to point to the new version.
sudo apt-get install ruby1-9 rubygems1-9
sudo ln -sf /usr/bin/ruby1-9 /usr/bin/ruby
Install later versions of Ruby in Ubuntu 18.04 using apt
How do I install the latest version of ruby in Ubuntu? - Stack Overflow
How to I update my version of ruby on Ubuntu?
Will you consider to use official snap Ruby packages instead of rvm/rbenv in production (ubuntu)?
Videos
Why not use ruby 2.3 which is available in the repositories for 16.04 and 17.10 with
sudo apt update
After the update is finished run:
sudo apt-get install ruby2.3 ruby2.3-dev
Or try ruby 2.4 or 2.5
You can get those via the brightbox PPA
Add the repository and update
sudo apt-add-repository ppa:brightbox/ruby-ng && sudo apt-get updateinstall
sudo apt-get install ruby2.4or for 18.04
sudo apt-get install ruby2.5 ruby2.5-dev
Information on the status of packages in the aforementioned PPA can be found on the “Brightbox” team launchpad page.
Alternatively you could try reverse hacking the error alternative path /usr/bin/ruby2.2 doesn't exist by creating it with sudo mkdir /usr/bin/ruby2.2 and trying again.
On Ubuntu 14.04 this worked for me to install ruby 2.4.1
sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev
Then install rbenv
cd
git clone git://github.com/sstephenson/rbenv.git .rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
Now install ruby 2.4.1
rbenv install -v 2.2.3
To set 2.4.1 as a default use command rbenv global 2.4.1.
I would like to install ruby version 2.7.4 using apt in Ubuntu 18.04. Using the below command:
sudo apt install ruby-full
But I am able to install only older versions. Is there a way to install the specified version using apt?
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 "*******************"
How to get a current Ruby version without messing up your system
Do not mess with your system Ruby, but instead install a current version with either rbenv or RVM. I prefer the first, but both work fine. Note that you can only install one of those at a time.
With such a Ruby version manager, you'll never have to type sudo again to install (or uninstall) a Gem, and you can keep different versions for different projects. You can safely remove these versions again.
Please make sure to read the READMEs of those tools, at least once.
Method 1 – rbenv
rbenv is a version manager for Ruby. It allows you to install a Ruby version alongside your original system Ruby, which means you cannot mess up that one, and you can easily upgrade versions.
To install it, use the rbenv-installer. Make sure to restart your shell once it's installed, and that the rbenv function works.
Then, once rbenv is installed, run rbenv install -l. This gives you a list of available Rubies. Install your chosen one with:
rbenv install 2.5.1
Now choose this one as your default:
rbenv global 2.5.1
As soon as this is done, gem can be used to run:
gem install rails
If the above does not work, you might be missing required packages for building from source. See here for a list of packages that you might want to install. On Ubuntu, these include:
sudo apt install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm5 libgdbm-dev
Method 2 – RVM
You can also install Ruby over RVM. Here as well, you don't need to sudo anything, and you'll be able to get more recent versions of Ruby alongside the system one.
Read the installation instructions for your system.
After installation, you can install Rubies with a simple command. First, check rvm list known to get the list of installable versions. Now install your choice:
rvm install 2.5.1
Then, set it as the default Ruby version for your user:
rvm use 2.5.1 --default
Now you can install Rails over gem:
gem install rails
There are multiple ways to install ruby on ubuntu, but installing form the repositories is (currently) not popular. To cleanly get a non-suffixed ruby, you should build ruby yourself or use rvm.