XINDI LI
XINDI LI

Reputation: 675

Rails: The program 'rails' is currently not installed on Ubuntu 16.04

I installed rvm ruby and gem. When I used gem to install rails, it's like this:

woyuxuxu123@ubuntu:~$ sudo gem install rails
[sudo] password for woyuxuxu123: 
Successfully installed rails-5.1.4
Parsing documentation for rails-5.1.4
Done installing documentation for rails after 0 seconds
1 gem installed

But when I enter rails -v, I got:

woyuxuxu123@ubuntu:~$ rails -v
The program 'rails' is currently not installed. You can install it by typing:
sudo apt install ruby-railties

I tried some solutions, but did not work for me, such as

source ~/.rvm/scripts/rvm

Someone mentioned the path. Here is how it looks

RubyGems Environment:
EXECUTABLE DIRECTORY: /usr/local/bin

woyuxuxu123@ubuntu:~$ echo $PATH
/home/woyuxuxu123/bin:/home/woyuxuxu123/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/woyuxuxu123/.rvm/bin:/home/woyuxuxu123/.rvm/bin

What should I do?

Upvotes: 2

Views: 1947

Answers (2)

Promise Preston
Promise Preston

Reputation: 28920

I faced a similar issue for Rails 5.2 and Ubuntu 18.04. I had an already setup server with Ruby and Rails installed, but I couldn't access them.

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

Upvotes: 1

yumitsu
yumitsu

Reputation: 599

Probably you forgot to add rvm script to your .bash_profile:

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"

Try running rvm repair all and then restart your terminal.

Upvotes: 0

Related Questions