How to install a gem globally without sudo using rbenv?
Basically, the problem was I did not add rbenv/bin/rbenv
to $PATH
.
export PATH="$HOME/.rbenv/bin:$PATH"
Better yet, add this to your .bashrc
or .bash_profile
to start every session with rbenv
.
After that, make sure to:
eval "$(rbenv init -)"
In order to enable shims and autocompletion.
fishshell
For those using fish, you can accomplish the same like this:
if status --is-interactive
. (rbenv init - | psub)
end
Now, if you don't like modifying $PATH
directly and have ownership over /usr/local/bin
, a more nifty solution is to symlink with ~/.rbenv/bin/rbenv
.
ln -s ~/.rbenv/bin/rbenv /usr/local/bin
ruby-build
As a final warning, make sure to install ruby-build
(a rbenv
plugin to add the install
command to rbenv
and be able to easily install Ruby versions.)
If you are using homebrew it's easy as pie:
brew install ruby-build
sudo gem install' or 'gem install' and gem locations
Contrary to all the other posts I suggest NOT using sudo
when installing gems.
Instead I recommend you install RVM and start a happy life with portable gem homes and different version of Ruby all living under one roof.
For the uninitiated, from the documentation:
RVM is a command line tool which allows us to easily install, manage and work with multiple ruby environments and sets of gems.
The reason why installing gems with sudo
is worse than just gem install
is because it installs the gems for ALL USERS as root
. This might be fine if you're the only person using the machine, but if you're not it can cause weirdness.
If you decide you want to blow away all your gems and start again it's much easier, and safer, to do so as a non-root user.
If you decide you want to use RVM
then using sudo
will cause all kinds of weirdness because each Ruby version you install through RVM
has its own GEM_HOME.
Also, it's nice if you can make your development environment as close to your production environment as possible, and in production you'll most likely install gems as a non-root user.
Installing Ruby on Rails and other gems without admin password.
You can use RVM or rbenv. Those are tools that manage your ruby environment (interpreter version, gems) and let you keep all the gems in user directories.
In short: install rvm or rbenv, then install ruby using one of them and then - you can install your gems without admin rights. You'll get an ability to upgrade ruby to the newest version for free :).
It looks you're using mac, so see this guide.
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.
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
Related Topics
How to Make a Non-Blocking Request for an Exclusive Lock Using File#Flock
How to Enter Password in a Popup Using Watir
Attempting to Install Libv8, "Failed to Build Gem Native Extension"
Split String Without Removing Delimiter
Ruby: How to Determine If File Being Read Is Binary or Text
Devise Authentication Gem: How to Save the Logged in User Id
Convert 12 Hr Time to 24 Hr Format in Ruby
Garbage Collector Tuning in Ruby 1.9
Dealing with Large CSV Files (20G) in Ruby
Openssl Error Installing Ruby 2.0.0-P195 on MAC with Rbenv
Rspec Testing Has_Many :Through and After_Save
Rails - Paperclip Validating Attachment Size When It Shouldn't Be
How to Configure Config.Yml So That I Can Install Devkit
Ruby on Rails Named Scope Implementation
Ruby, Run Linux Commands One by One, by Ssh and Log Everything