Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to install gems without sudo

Tags:

ruby

gem

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 
like image 440
murtaza52 Avatar asked Jul 25 '12 06:07

murtaza52


People also ask

How do I install gem packages?

With the --local ( -l ) option, you would perform a local search through your installed gems. To install a gem, use gem install [gem] . Browsing installed gems is done with gem list . For more information about the gem command, see below or head to RubyGems' docs.

What command is used for installing gem file in Terminal?

The install command installs local or remote gem into a gem repository. For gems with executables ruby installs a wrapper file into the executable directory by default. This can be overridden with the –no-wrappers option.


2 Answers

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

like image 72
Pedro Nascimento Avatar answered Sep 23 '22 12:09

Pedro Nascimento


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)

like image 45
Joshua Cheek Avatar answered Sep 22 '22 12:09

Joshua Cheek