This issue arose for me when working on an already setup Ubuntu 18.04 server with Ruby 2.5.0 and Rails 5.2 installed.
The error output was:
The program 'rails' is currently not installed. You can install it by typing:
sudo apt install ruby-railties
The issue is simply caused by the rails executable not being globally accessible by programs.
Here's how I solved it
Note: If you are working on a production server, endeavour to make a backup of your database before trying out the solution below to avoid data loss.
For my case, my version manager was rbenv and not rvm
Re-install rbenv itself. Clone the rbenv repository from GitHub into the directory ~/.rbenv:
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
Next, add ~/.rbenv/bin to your $PATH so that you can use the rbenv command line utility. Do this by altering your ~/.bashrc file so that it affects future login sessions:
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
Then add the command eval "$(rbenv init -)" to your ~/.bashrc file so rbenv loads automatically:
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
Next, apply the changes you made to your ~/.bashrc file to your current shell session:
source ~/.bashrc
Verify that rbenv is set up properly by using the type command, which will display more information about the rbenv command:
type rbenv
Your terminal window will display the following:
rbenv is a function
rbenv ()
{
local command;
command="${1:-}";
if [ "$#" -gt 0 ]; then
shift;
fi;
case "$command" in
rehash | shell)
eval "$(rbenv "sh-$command" "$@")"
;;
*)
command rbenv "$command" "$@"
;;
esac
}
If everything worked right, running the command below will display the versions of Ruby and Rails previously installed on your machine:
ruby -v
rails -v
Else, run a fresh installation of Ruby and Rails on your machine.
That's all
I hope this helps