Can't install Ruby rvm on Ubuntu 16.04 due to gpg bug

After trying many ways. I did succeed to install rails as follows:

$ \curl -sSL https://get.rvm.io | bash
$ source /home/<user>/.rvm/scripts/rvm
$ rvm -v
$ rvm install ruby
$ ruby -v
$ sudo apt-get install rubygems
$ gem update
$ sudo apt-get install ruby-dev zlib1g-dev liblzma-dev build-essential patch
$ rvm gemset list
$ gem install rails
$ rails -v

Where "user" is my username


I am just posting an update solution for it as I faced the same issue in Ubuntu 18.04 while trying to fetch keys for RVM.

The following method is provided by RVM.

gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

If it doesn't work out and you try to install rvm directly, the process will fail and provides three suggestions to receive keys. One of which have a step to receive the keys with gpg2.

Install gpg2 in your system before that.

sudo apt install gnupg2

The command is

gpg2 --recv-keys 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

But this command too will not work. So here's an alternative. Just replace the gpg from the older command to gpg2 which worked for me.

gpg2 --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

In addition to the previous answers, if you are behind a firewall, the following command might not work for you.

gpg2 --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

In that case, you can use the following command to get the keys -

sudo apt-key adv --keyserver hkp://keys.gnupg.net:80 --recv-keys <<key>> <<key>>