I have ruby installed on my ubuntu 16.04.
$which ruby
/usr/bin/ruby
$ruby -v
ruby 2.3.0p0 (2015-12-25) [x86_64-linux-gnu]
$gem install bundler
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /var/lib/gems/2.3.0 directory.
Any help will be greatly appreciated!
If you want to use the distribution Ruby instead of rb-env/rvm, you can set up a
GEM_HOME
for your current user. Start by creating a directory to store the Ruby gems for your user:Then update your shell to use that directory for
GEM_HOME
and to update yourPATH
variable to include the Ruby gem bin directory.(That last line will load the settings directly into your current shell.)
Now you should be able to install Ruby gems under your user using the
gem
command. I was able to get this working with Ruby 2.5.1 under Ubuntu 18.04. If you are using a shell that is not Bash, then you will need to edit the startup script for that shell instead ofbashrc
.Rather than changing owners, which might lock out other local users, or –some day– your own ruby server/deployment-things... running under a different user...
I would rather simply extend rights of that particular folder to... well, everybody:
(I did encounter your error as well. So this is fairly verified.)
Building on derek's answer above, it is generally not recommended to use the system provided Ruby instance for your own development work, as system tools might depend on the particular version or location of the Ruby install. Similar to this answer for Mac OSX, you will want to follow derek's instructions on using something like rbenv (RVM is a similar alternative) to install your own Ruby instance.
However, there is no need to uninstall the system version of Ruby, the rbenv installation instructions provide a mechanism to make sure that the instance of Ruby available in your shell is the rbenv instance, not the system instance. This is the
line in derek's answer.
Try using
chown -R
on thevar/lib/gems
directory, assigning ownership to the user [rubyusername
] in this example, the user that will be installing and developing with gems.This recursively changes everything under the gems directory. For extra security on multi-user systems, you can also create a group, rather than chowning the individual rubyusername, and add users to that group.
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:
The last step is to install Bundler:
Then enjoy!
Derek