1

Can't install Ruby, I used the command lines below before:

sudo apt install -y build-essential tklib zlib1g-dev libssl-dev libffi-dev libxml2 libxml2-dev libxslt1-dev libreadline-dev

git clone https://github.com/rbenv/rbenv.git ~/.rbenv

git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
exec zsh

Thank tried to run: rbenv install 3.0.3

But keep getting this error:

Downloading ruby-3.0.3.tar.gz...
-> https://cache.ruby-lang.org/pub/ruby/3.0/ruby-3.0.3.tar.gz
error: failed to download ruby-3.0.3.tar.gz

BUILD FAILED (Ubuntu 20.04 using ruby-build 20220324)
1
  • Hello. What does this statement from your question mean? <Thank tried to run> The error is pretty clear in the path you have given there is no such app named that. Use a browser go to the directory and verify it is there and or what the name should be.
    – David DE
    Commented Apr 4, 2022 at 8:16

3 Answers 3

5

Apparently Ubuntu and its newer derivatives come with OpenSSL 3.0 and in this case Ruby versions earlier than 3.1 used OpenSSL 1.1

In this case, the safest option is to follow the user manual and manually compile OpenSSL 1.1.

It worked for me too with Pop!_OS and asdf

PS: I put the export inside my .zshrc

Install the dependencies:

sudo apt install build-essential checkinstall zlib1g-dev

Download OpenSSL 1.1.1:

cd ~/Downloads
wget https://www.openssl.org/source/openssl-1.1.1n.tar.gz
tar xf openssl-1.1.1n.tar.gz

Compile it:

cd ~/Downloads/openssl-1.1.1n
./config --prefix=/opt/openssl-1.1.1n --openssldir=/opt/openssl-1.1.1n shared zlib
make
make test
sudo make install

Link the system's certs to OpenSSL 1.1.1 directory:

sudo rm -rf /opt/openssl-1.1.1n/certs
sudo ln -s /etc/ssl/certs /opt/openssl-1.1.1n

Use RUBY_CONFIGURE_OPTS=--with-openssl-dir=/opt/openssl-1.1.1n before the command to install the ruby version:

RUBY_CONFIGURE_OPTS=--with-openssl-dir=/opt/openssl-1.1.1n rbenv install 2.7.6

If you want to make this permanent, add this line to you .bashrc or .zshrc file:

export RUBY_CONFIGURE_OPTS="--with-openssl-dir=/opt/openssl-1.1.1n/"

Then you don't need to use RUBY_CONFIGURE_OPTS=--with-openssl-dir=/opt/openssl-1.1.1n before the command anymore.

Font: https://github.com/rbenv/ruby-build/discussions/1940#discussioncomment-2663209

2
  • 1
    I tried with openssl1.0.2u before but it didnt work. This one worked!
    – EReload
    Commented May 2, 2022 at 9:43
  • 1
    Wish I'd found this a few hours ago! I saw the version change, but ignored it because I thought I was long past that as an issue today. Not true!
    – codenoob
    Commented May 7, 2022 at 16:57
1

For ruby-build 20240119 you'll need to do this:

#For 'BUILD FAILED (Ubuntu 22.04 on x86_64 using ruby-build 20240119)'

:~$ sudo apt install \
build-essential libxml2 libssl-dev libffi-dev \
libffi8 libyaml-dev libreadline-dev

Then:

asdf install ruby 3.2.3
0

Install Ruby and Ruby environment newer than the Ubuntu rbenv package.

sudo apt install rbenv

rbenv install -l | grep VERSION

Check your preferable version is available or not.


If it's not, you can update latest list from git and remove ruby package of ubuntu beforehand (for making this simple).

cd $HOME

git clone https://github.com/sstephenson/rbenv.git .rbenv

git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build

Check your version available. Before install new environment, you must tell a new path to the shell

Add this code at the end of .bash_profile

# For rbenv
export PATH="$HOME/.rbenv/bin:$PATH" 
eval "$(~/.rbenv/bin/rbenv init -)"

Restart your terminal or source .bash_profile If the path of rbenv correctly set by which rbenv, it replies /home/USER/.rbenv/bin/rbenv

rbenv install VERSION
rbenv rehash
rbenv global VERSION


Confirmation

$ ruby -v

ruby 3.0.3p157 (2021-11-24 revision 3fb7d2cadc) [x86_64-linux]

$ which ruby

/home/USER/.rbenv/shims/ruby

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .