6

I have installed Ubuntu 12.04 on VirtualBox.

I installed rvm, ruby and rails following this tutorial.

But when I restart, I am getting this error:

The program 'rails' is currently not installed.  You can install it by typing:
sudo apt-get install rails

And after that, when I again try gem install rails I am getting this error:

ERROR:  While executing gem ... (Errno::EACCES)
Permission denied - /var/lib/gems

And there is no gems folder under /var/lib/.

Can anyone help me to fix this?

Karlis
  • 213

3 Answers3

6

gem install rails needs to be run as root since /var/lib/gems should be 0644 or something. Therefore, use:

sudo gem install rails
nanofarad
  • 20,906
0

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

0

There is a couple ways to install rails, one is straight from apt and another from ruby gems.

apt-get install ruby-rails-3.2

This isn't the best way to install rails, it's better to have ruby gems handle rails for you. First make sure that ruby and ruby gems are up to date

$ ruby -v && gem -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
1.8.23

Run

$ apt-get update && apt-get upgrade

To get the latest versions.
NOTE: You got his error

PERMISSION DENIED

Run the exact command with sudo prepended to the command so

sudo gem install rails

Should be the correct way to install rails.

Be careful when using the sudo command, make sure you know what you are doing. As the saying goes "With great power comes great responsibility" and sudo is no exception.

iridian
  • 389