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

11,142

Solution 1

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]

Solution 2

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.

Share:
11,142
Graham Nicholls
Author by

Graham Nicholls

Liberal, lefty Christian. Love music, sport (playing it - what's the point of watching someone else have fun?), reading. Actually, I do enjoy watching cricket, but that's special. Been programming since I was around 14 years old - so about 40 years - where did the time go? Been using Unix, then Linux for all my professional life. Ruby is my favourite language, but I'm trying to find the time to learn go, which I suspect is going to be "bigger than Java" (I certainly hope so). Teach Unix/Linux/AWS/Python for Learningtree; have taught in the UK, USA, Germany Belgium, Sweden, Ireland & Canada. Hello, if we've met on a course - I hope it helped you in your career.

Updated on June 12, 2022

Comments

  • Graham Nicholls
    Graham Nicholls almost 2 years

    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.

  • Graham Nicholls
    Graham Nicholls over 6 years
    This is (K)Ubuntu 17.10 by the way
  • Graham Nicholls
    Graham Nicholls over 6 years
    Added the brightbox ppa. Then tried to run apt install ruby2.4 ruby2.4-dev no packages found