user2843054
user2843054

Reputation: 31

Permission errors installing gems on linux

Seems like only root can use ruby gems (?)

$ gem list

*** LOCAL GEMS ***

$ gem install json
ERROR:  While executing gem ... (Errno::EACCES)
Permission denied - /var/lib/gems/1.9.1

I have no gems and can't install any...

$ sudo gem install json
[sudo] password for bill: 
Building native extensions.  This could take a while...
Successfully installed json-1.8.0
1 gem installed
Installing ri documentation for json-1.8.0...
Installing RDoc documentation for json-1.8.0...

$ sudo gem list

*** LOCAL GEMS ***

json (1.8.0)                    

Root can install and view gems

$ gem list

*** LOCAL GEMS ***

But my user can't see them...

Is there a way for non-root users use gems on linux?

-- SOLUTION --

Thanks for the comments suggesting I check /var/lib/gems/1.9.1 permissions

I'd already checked them, but missed /var/lib/gems on the way

/var/lib/gems# ls -al
total 12
drwxr-x---  3 root root 4096 Oct  3 09:13 .
drwxr-xr-x 59 root root 4096 Oct  3 09:13 ..
drwxr-xr-x  6 root root 4096 Oct  3 09:13 1.9.1

chmod o+rx /var/lib/gems/

I can now use the gems already installed there

Upvotes: 3

Views: 3652

Answers (1)

Jake Plimack
Jake Plimack

Reputation: 44

no, you shouldn't try rvm or rbenv as they are both terrible. chruby is very lightweight and the best of a bad situation.

the answer is you should need sudo to install system-wide gems. set GEM_HOME to ~/.gems or /path/to/app/.gems to install the gems per-user or per-app

Upvotes: 1

Related Questions