Showing posts with label rvm. Show all posts
Showing posts with label rvm. Show all posts

2023-11-27

Install Ruby 2.7 on Ubuntu 22.04

So I have a past project from 2014 that still running until now (5 independent services: 3 written in Golang - 2 read-only service, 2 write-only service written in Ruby, 1 PostgreSQL, 1 Redis, ~45GB database / 2.7GB daily backup, 1.1GB cache, 8GB logs, <800MB compressed), and the server RAID already near death (since the server was alive without issue for 12 years), and on new server there's freshly installed 22.04, and old service when trying to be run with ruby 3.x will always failed because of library compilation issues (eg. still depend on outdated postgres12-dev). Here's how you can install ruby 2.8 without rvm:

# add old brightbox PPA (must be focal, not jammy)
echo 'deb https://ppa.launchpadcontent.net/brightbox/ruby-ng/ubuntu focal main
deb-src https://ppa.launchpadcontent.net/brightbox/ruby-ng/ubuntu focal main ' > /etc/apt/sources.list.d/brightbox-ng-ruby-2.7.list

# add the signing key
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys F5DA5F09C3173AA6

# add the focal security for libssl1.1
echo "deb http://security.ubuntu.com/ubuntu focal-security main" | sudo tee /etc/apt/sources.list.d/focal-security.list

# update and install
sudo apt update
sudo apt install -y ruby2.7 ruby2.7-dev

 

that's it, now you can run gem install (with sudo for global) without any compilation issue as long as you have correct C library dependency (eg. postgresql-server-dev-12).

2014-07-28

Installing Ruby 2.1+ on Ubuntu (via RVM)

On some distro, Ruby interpreter was out of date

apt-cache show ruby2.0 | grep Version
Version: 2.0.0.484-1ubuntu2

And we want the latest version, we could use Brightbox's PPA:

# install add-apt-repository command
sudo apt-get install software-properties-common python-software-properties

# add brightbox's repository
sudo apt-add-repository ppa:brightbox/ruby-ng

# update list of available software
sudo apt-get update

# install ruby
sudo apt-get install ruby2.1

Or use RVM, the Ruby Version Manager, that could be installed using these commands:

# install rvm
curl -sSL https://get.rvm.io | bash

# use rvm (or relogin/restart bash, since it's inserted into .bashrc)
source /etc/profile.d/rvm.sh

to see the list of available version, we could use:

rvm list known

to install the latest version, run this command:

rvm install ruby-2.1.2
ruby-2.1.2 - #removing src/ruby-2.1.2..
ruby-2.1.2 - #removing rubies/ruby-2.1.2..
Searching for binary rubies, this might take some time.
Found remote file https://rvm.io/binaries/ubuntu/14.04/x86_64/ruby-2.1.2.tar.bz2
Checking requirements for ubuntu.
Requirements installation successful.
ruby-2.1.2 - #configure
ruby-2.1.2 - #download
######################################################################## 100.0%
ruby-2.1.2 - #validate archive
ruby-2.1.2 - #extract
ruby-2.1.2 - #validate binary
ruby-2.1.2 - #setup
ruby-2.1.2 - #gemset created /usr/local/rvm/gems/ruby-2.1.2@global
ruby-2.1.2 - #importing gemset /usr/local/rvm/gemsets/global.gems....................................
ruby-2.1.2 - #generating global wrappers........
ruby-2.1.2 - #gemset created /usr/local/rvm/gems/ruby-2.1.2
ruby-2.1.2 - #importing gemsetfile /usr/local/rvm/gemsets/default.gems evaluated to empty gem list
ruby-2.1.2 - #generating default wrappers........
Making gemset ruby-2.1.2 pristine.............................................................
Making gemset ruby-2.1.2@global pristine..............................................................


Voila, done! now we could use it using this command:

rvm use ruby-2.1.2 

ruby --version
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]

gem install pry
Fetching: coderay-1.1.0.gem ( 52%)
Fetching: coderay-1.1.0.gem (100%)
Successfully installed coderay-1.1.0
Fetching: slop-3.6.0.gem (100%)
Successfully installed slop-3.6.0
Fetching: method_source-0.8.2.gem (100%)
Successfully installed method_source-0.8.2
Fetching: pry-0.10.0.gem (100%)
Successfully installed pry-0.10.0
invalid options: -SNw2
(invalid options are ignored)
Parsing documentation for coderay-1.1.0
Installing ri documentation for coderay-1.1.0
Parsing documentation for method_source-0.8.2
Installing ri documentation for method_source-0.8.2
Parsing documentation for pry-0.10.0
Installing ri documentation for pry-0.10.0
Parsing documentation for slop-3.6.0
Installing ri documentation for slop-3.6.0
Done installing documentation for coderay, method_source, pry, slop after 4 seconds
4 gems installed