How to Install a Gem or Update Rubygems If It Fails With a Permissions Error

How to install a gem or update RubyGems if it fails with a permissions error

You don't have write permissions into the /Library/Ruby/Gems/1.8 directory.

means exactly that, you don't have permission to write there.

That is the version of Ruby installed by Apple, for their own use. While it's OK to make minor modifications to that if you know what you're doing, because you are not sure about the permissions problem, I'd say it's not a good idea to continue along that track.

Instead, I'll strongly suggest you look into using either rbenv or RVM to manage a separate Ruby, installed into a sandbox in your home directory, that you can modify/fold/spindle/change without worrying about messing up the system Ruby.

Between the two, I use rbenv, though I used RVM a lot in the past. rbenv takes a more "hands-off" approach to managing your Ruby installation. RVM has a lot of features and is very powerful, but, as a result is more intrusive. In either case, READ the installation documentation for them a couple times before starting to install whichever you pick.

Installing gem fails with permissions error

Use a Ruby version manager, like RVM or rbenv.

I can't speak for rbenv, but RVM prepends a Ruby version-specific bin to your PATH that you have access to, so you don't have to use sudo (which is how you could install gems in your current situation, but is highly discouraged).

rbenv similarly prepends to your $PATH, but it uses a shim.

gem install permission problem

For a systemwide Ruby install, become root. For example:

$ sudo gem install hpricot

However, the modern approach in many circumstances, including in development, is to use a tool that lets you easily install and use Ruby as a normal user. This lets you avoid having to become root. There are a few such tools, and the one I use is RVM.

# install rvm into your ~
$ \curl -sSL https://get.rvm.io | bash -s stable

# install latest version of ruby into your ~
$ rvm install ruby

# installs a gem into your ~
$ gem install $SOME_GEM_NAME

Getting permission denied error when I run gem install bundler

you are using the system's ruby and now you need to root level permission to to install bundler. Sudo enables root privileges. Check if your account has root privileges.

I prefer using a version and manager like rbenv. Install rbenv . then install the required version of ruby and then install bundler.

You don't have write permissions for the /var/lib/gems/2.3.0 directory

You first need to uninstall the ruby installed by Ubuntu with something like sudo apt-get remove ruby.

Then reinstall ruby using rbenv and ruby-build according to their docs:

cd $HOME
sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libxml2-dev libxslt1-dev libcurl4-openssl-dev libffi-dev

git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL

git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL

rbenv install 2.3.1
rbenv global 2.3.1
ruby -v

The last step is to install Bundler:

gem install bundler
rbenv rehash

During gem update I get permissions error for /usr/bin directory

It is highly recommended to use a ruby version manager so you never have to mess with trying to update system ruby i.e. avoid sudo gem update

These are widely used in the ruby community.

https://rvm.io/rvm/install

https://github.com/rbenv/rbenv

If you have installed a version manager, than it's likely something wrong with your $PATH variable. See my comment on your question.



Related Topics



Leave a reply



Submit