Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best way to install ruby 2.4 on (K)Ubuntu 17.10?

Tags:

linux

ruby

ubuntu

I run Kubuntu, and would like to install the latest stable Ruby version, which as of writing is 2.4.2. Unfortunately, the Ubuntus are a bit behind: 17.10 has this:

$ ruby --version  
  ruby 2.3.3p222 (2016-11-21) [x86_64-linux-gnu]  
$

I've googled, and seen lots of suggestions none of which are elegant. I don't want to use rvm (nothing wrong with it - I just want my "base" ruby updated). Building from source is OK, except that it will default at least, to installing under /usr/local somewhere, and will leave the old version in place. I'd like to upgrade to 2.4.2 - possibly using rvm to install 2.5.

I've have already tried using the suggestion in the comment below. The ppa doesn't seem to have 2.4. When I use apt install ruby 2.4*, the * is a regex, so matches 2.{anything_or_nothing}, so tries to pull in 2.3, which is not what I want - eg

$ sudo apt install ruby2.4*
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'ruby2.3' for regex 'ruby2.4*'
Note, selecting 'uwsgi-plugin-rack-ruby2.3' for regex 'ruby2.4*'
Note, selecting 'ruby2.3-dev' for regex 'ruby2.4*'
Note, selecting 'ruby2.3-doc' for regex 'ruby2.4*'
Note, selecting 'libruby2.3' for regex 'ruby2.4*'
Note, selecting 'ruby-ruby2ruby' for regex 'ruby2.4*'
Note, selecting 'ruby2.3-tcltk' for regex 'ruby2.4*'
libruby2.3 is already the newest version (2.3.3-1ubuntu1).
ruby2.3 is already the newest version (2.3.3-1ubuntu1).
ruby2.3-dev is already the newest version (2.3.3-1ubuntu1).
ruby2.3-dev set to manually installed.
The following additional packages will be installed:
  libmatheval1 ruby-parser ruby-sexp-processor uwsgi-core
Suggested packages:
  nginx-full | cherokee | libapache2-mod-proxy-uwsgi | libapache2-mod-uwsgi | libapache2-mod-ruwsgi uwsgi-plugins-all uwsgi-extra
The following NEW packages will be installed
  libmatheval1 ruby-parser ruby-ruby2ruby ruby-sexp-processor ruby2.3-doc ruby2.3-tcltk uwsgi-core uwsgi-plugin-rack-ruby2.3
0 to upgrade, 8 to newly install, 0 to remove and 44 not to upgrade.
Need to get 4,444 kB of archives.
After this operation, 34.5 MB of additional disk space will be used.
Do you want to continue? [Y/n] n
Abort.

Thank you.

like image 598
Graham Nicholls Avatar asked Oct 31 '17 14:10

Graham Nicholls


People also ask

How do I install a specific version of Ruby Ubuntu?

To install and use a different version of Ruby, run the rbenv commands with a different version number, as in rbenv install 2.3. 0 followed by rbenv global 2.3. 0 . You now have at least one version of Ruby installed and have set your default Ruby version.

Where is Ruby installed on Ubuntu?

One way open the terminal window (sometimes called a "shell" or "bash shell") is to select Applications > Accessories > Terminal. Run the command which ruby. If you see a path such as /usr/bin/ruby, Ruby is installed.


2 Answers

Just add our repository, if you haven’t already:

$ sudo apt-add-repository ppa:brightbox/ruby-ng

$ sudo apt-get update

Install the packages:

$ sudo apt-get install ruby2.4 ruby2.4-dev

And you’re up and running:

$ ruby2.4 -v

ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux-gnu]

like image 198
dburcu Avatar answered Oct 06 '22 02:10

dburcu


Please do yourself a favor and install Ruby using RVM or rbenv.

Both solutions allow multiple Ruby versions to be installed alongside each other and offer an easy way out (rvm implode for example removed all traces of RVM without messing up your system) in case you mess something up.

If you REALLY want to install Ruby not using any version managers then your best bet would be: sudo apt-get build-dep ruby2.3 and compiling Ruby from source.

like image 29
Michał Zając Avatar answered Oct 06 '22 02:10

Michał Zając