how to install gems without sudo

sudo gem install
install rvm
you don't have write permissions for the /library/ruby/gems/2.3.0 directory
install ruby
install gem mac
install rubyubuntu
add ruby to path mac
gem install rvm

On all my gem installs I have to do sudo ? So

sudo gem install rails

will work, while only

gem install rails

will not work. How do I remedy it ?

I have rvm installed -

murtaza@murtaza-dev:~$ which rvm
/home/murtaza/.rvm/bin/rvm

murtaza@murtaza-dev:~$ which gem
/home/murtaza/.rvm/rubies/ruby-1.9.3-p194/bin/gem

However I am also getting this warning when I do any operations with gem -

murtaza@murtaza-dev:~$ gem
/home/murtaza/.rvm/rubies/ruby-1.9.3-p194/bin/gem:4: warning: Insecure world writable dir /opt in PATH, mode 040777

EDIT

I have reinstalled rvm using curl -L get.rvm.io | bash -s stable --auto (without sudo).

However still when I try installing gem it gives me the following error -

murtaza@murtaza-dev:~$ gem install rails
/home/murtaza/.rvm/rubies/ruby-1.9.3-p194/bin/gem:4: warning: Insecure world writable dir /opt in PATH, mode 040777
ERROR:  While executing gem ... (Errno::EACCES)
    Permission denied - /home/murtaza/.gem/specs

EDIT

I did chown on the whole thing but still getting the error -

murtaza@murtaza-dev:~$ sudo chown murtaza.murtaza -R ~/.rvm/*


 murtaza@murtaza-dev:~$ gem install rails
    /home/murtaza/.rvm/rubies/ruby-1.9.3-p194/bin/gem:4: warning: Insecure world writable dir /opt in PATH, mode 040777
    ERROR:  While executing gem ... (Errno::EACCES)
        Permission denied - /home/murtaza/.gem/specs

Use chown on the whole .rvm and .gem directories back to your user. You probably used sudo before and it screwed up permissions.

sudo chown -R username:group ~/.rvm
sudo chown -R username:group ~/.gem

Of course, change username to your username and group to your group

Bundler cannot install any gems without sudo, You may host gems in your user home folder, that does not need root permissions: bundle install --path ~/.gem. To avoid passing this  Configuring a new machine (Mac OS Mojave - Version 10.14.2). After installing ruby with rbenv. I'm trying to install some gem and running : gem install rake bundler rspec rubocop pry pry-byebug

When you install them without sudo, Ruby doesn't know where they get installed to. I can't remember where it installs them by default, probably somewhere like ~/.gems or something. Anyway, you can tell Ruby that's where they're installed by setting the GEM_HOME environment variable.

$ # assuming your gems are stored in ~/.gems
$ GEM_HOME="$HOME/.gems" ruby my_program.rb

If that works, then you might put it in your ~/.bashrc (there are a number of possible files this could go in, depending on your system)

Install Ruby Gems on Mac OS X without sudo, I have never had a default installation of Ruby gems on Mac OS X let me simplyinstall new gems without requiring sudo. If you would like to  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

For Mac users, this works for me...

  1. Add GEM_HOME to your .bash_profile

For example, nano ~/.bash_profile and add export GEM_HOME=/Users/Michael/.gem where the path is to your own Home folder

  1. Add the gem executables to your system path

Also in .bash_profile, add export PATH="$GEM_HOME/bin:$PATH"

Source: http://michaelehead.com/2016/02/06/installing-gems-without-sudo.html

How to install ruby gems without sudo, RVM: From the rvm.io homepage, I used: \curl -sSL https://get.rvm.io | bash -s stable . This worked fine for me, no admin permissions needed. I have installed rbenv using Homebrew. $ rbenv local 2.4.0 $ rbenv global 2.4.0 $ ruby -v ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-darwin16] When I check the Rails version I get the

You should install Ruby Version Manager. It stores installed rubies and gems in your home dir, so now you don't have to use sudo to install gems. It has a lot more features besides this. :)

RVM system gems without sudo, System Ruby has a problem, though: it is hardcoded to install gem executables into Install gems without sudo, and everything is good. You can also install gems in your local environment (without sudo) with I recommend that so you don't mess with your system-level configuration even if it's a single-user computer. You can check where the gems go by looking at gempaths with gem environment. In my case it's "~/.gem/ruby/1.8".

I resolved my issue in the following way: (I have ubuntu 17.10)

Open terminal and type:

echo "gem: --user-install" >> ~/.gemrc

Then add ruby's bin path in .bashrc file

export PATH="$PATH:$HOME/.gem/ruby/x.x.x/bin"

Install ruby gems without sudo · GitHub, Install ruby gems without sudo. gems.sh. # tested with ruby 2.4. install ruby and nodejs from your distribution repository(ubuntu also requires  Following yesterday’s post about using “npm install -g” without root privileges, here are the Python and Ruby counterparts for your beloved OSX or Linux box. By default, pip install and gem install try to install stuff in /usr/ , which requires root privileges.

Install Ruby Gems without sudo, Sudo is not needed to install Ruby Gems in the home directory with this procedure. When you install them without sudo, Ruby doesn't know where they get installed to. I can't remember where it installs them by default, probably somewhere like ~/.gems or something. Anyway, you can tell Ruby that's where they're installed by setting the GEM_HOME environment variable.

"pip install" & "gem install" without sudo, Following yesterday's post about using “npm install -g” without root privileges, here are the Python and Ruby counterparts for your beloved OSX  Without sudo it installs in your home directory (~/.gems) so if you don't have your home directory install in your path or a different user is running your ruby script (like passenger/apache), it won't be able to load the gems. level 1 4 points · 9 years ago

Bare Metal Ruby, Step 2. Make gem work without sudo. By default, gem will try to install new gems to the system folder (e.g. /var/lib/gems/2.4.0 ), which is no good  While the --without option will skip installing the gems in the specified groups, it will still download those gems and use them to resolve the dependencies of every gem in your Gemfile (5). This is so that installing a different set of groups on another machine (such as a production server) will not change the gems and versions that you have

Comments
  • please, dont install gems with sudo, USE RVM !!! or any other ruby version mannager
  • For the warning, let's see if this answer will help.
  • Your chown looks odd to me. Shouldn't it be murtaza:murtaza?
  • Done but still the error. However I checked the ~/.gem dir, and it doesnt have a specs file in the first place. What should I do ?
  • possible duplicate of 'sudo gem install' or 'gem install' and gem locations
  • Sorry, chown your ~/.gem.
  • I resolved a similar issue using this suggestion, and with the -R recursive flag.
  • how do I know what to put for "group" ?
  • do an ls -l on any directory in your home folder (even the home folder itself) and you'll probably find out.
  • You can also run sudo rvm fix-permissions username:groupname