I'm trying to install rubyrep on CentOS, and when executing sudo gem install rubyrep I get the error sudo: gem: command not found. Sudo and gem are both installed and working, just not when combined.
My setting:
[rubyrep]# which sudo
/usr/bin/sudo
[rubyrep]# which gem
/usr/local/rvm/rubies/ruby-2.1.2/bin/gem
[rubyrep]# which ruby
/usr/local/rvm/rubies/ruby-2.1.2/bin/ruby
[rubyrep]# $PATH
-bash: /usr/local/rvm/gems/ruby-2.1.2/bin:/usr/local/rvm/gems/ruby-2.1.2#global/bin:/usr/local/rvm/rubies/ruby-2.1.2/bin:/usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin: No such file or directory
Try without sudo. You should only use sudo if you did a root installation of ruby, which is not recommended.
From http://web.archive.org/web/20130405074724/http://www.kleinfelter.com/node/188:
There are hundreds of reports on the net about "sudo: gem: command not
found". Out of the dozen or so I looked at, the suggested resolution
amounted to "ensure that 'gem' is in your PATH."
Yep. It is in my path. That is to say, the following works:
gem --help
but the following fails:
sudo gem --help
Further confusing matters, gem is in the path shown by:
sudo echo $PATH
The trick is that sudo doesn't use $PATH for its path on some editions
of Linux. This behavior is considered "more secure." (See
sudo changes PATH - why? ).
Bah! It is still a pain to work around. You have to get 'gem' into
the path (not simply the $PATH!) You'll read about options you can
pass to sudo, and that is fine and dandy when you type the
command-line yourself. When someone's script invokes sudo for you,
you're stuck with the command line that it uses.
I fixed it by doing:
alias sudo='sudo env PATH=$PATH'
as suggested in sudo changes PATH - why?.
sudo env PATH=$PATH gem install rails
It works for me.
If anyone runs across this, like I did, and the without sudo isn't an option. You may want to check your sudoers for the 'secure_path'.
If this doesn't include the path of your installation/gem/ruby (which gem). Then you'll also get this error.
Fedora 23, built from source.
Related
This all started by attempting to install cocoapodsthrough the terminal. Long story short, I kept getting an error that my rubygems version was not acceptable. I then attempted to update that version but kept getting the error:
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/bin directory.
I found a solution that worked: sudo gem install -n /usr/local/bin rubygems-update
The issue is that now EVERY time I install anything via terminal, I have to use sudo gem install -n /usr/local/bin. Which I do not remember ever being the case (but I may be incorrect). Is there a solution to negate having to enter in that full line every time I install something via terminal? Thanks for any help!
I recently switched over from windows pc to mac for development and i´m looking for some help regarding the terminal.
When i try to install compass wich is a ruby gem, i´m met with this error:
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/1.8 directory.
Is there a way for me to execute gem installments etc without doing sudo?
I found out that this "sudo chown -R $USER /usr/local" worked for npm. Now im looking for a way to do the same with ruby and yeoman.
As the commenters have pointed out, it is recommended that you try to use rvm or its cousins, to install ruby into your home directory, this way, you dont need root to install gems by default, and this is more widely recommended.
Alternatively you could try the same chown trick here
try
sudo chown -R <username>:<username> /Library/Ruby/Gems
The second one is usually group name, it can be skipped, or you can let it stay.
Hi People I am trying to install a gem file through command prompt on MAC using the following command "gem install filename" but whenever I try to execute the command I get the following error
WARNING: Installing to ~/.gem since /Library/Ruby/Gems/1.8 and
/usr/bin aren't both writable.
WARNING: You don't have /Users/hemmanshu/.gem/ruby/1.8/bin in your PATH,
gem executables will not run.
ERROR: Error installing frank-cucumber-0.8.14:
cucumber requires gherkin (~> 2.10.0, runtime)
every time I try to execute this command the same thing pops up.
You need to install gems with superuser privileges so you should to use
sudo gem install [gemname]
instead of
gem install [gemname]
U try with sudo. like "sudo gem install filename"
...Most of the time this is a PATH issue, Suppose you are using zshell as me, then add this line at the end of ~/.zshrc file
export PATH="$PATH:$HOME/.gem/ruby/2.1.0/bin"
If you are using bash as default shell then add this line to end of ~/.bashrc file
export PATH="$PATH:$HOME/.gem/ruby/2.1.0/bin"
For your case it will be like this:
export PATH="$PATH:$HOME/.gem/ruby/1.8/bin
Lastly don't forget to reload the shell by source ~/.zshrc incase of z-shell or source ~/.bashrc incase of bash-shell. I think this helps someone.
I have made a script that is already working properly in my development environment with RVM. This script reads *.eml files and parses them.
Now, my problem is this. When I transfer it to the production server, it gives a Permission denied - filename.eml (Errno::EACCES) when reading some files. When I manually read these files using sudo nano filename.eml, it is readable so I thought running my ruby script with sudo is the answer.
But when I tried running it with sudo ruby scriptname.rb, this time it gives me a cannot load such file -- mail (LoadError).
The mail gem is clearly installed and is shown both in gem list --local and sudo gem list --local.
The ruby versions are identical with or without sudo (1.9.3).
The mail gem is also accessible using sudo irb then typing require 'mail'.
Both development and production environments are on a Mac OS with RVM-managed ruby versions.
Any help will be greatly appreciated. Thanks.
maybe the gem is not readable for your server user, such as 'wwwroot', so please make sure the file is 775 mode. e.g.
cd $GEM_HOME
sudo chmod 755 -R .
then everything is readable for other group's users.
I have a machine that is running Ubuntu Hardy, which provides its own RubyGems package. Unfortunately that version of RubyGems (1.1.1) is too old to do anything useful with, so I decided to manually update RubyGems to the current version (1.3.6). That part went smoothly, and if I do gem -v, I get 1.3.6 which is expected. The problem is when I try to do: sudo gem install rack, it returns this error:
ERROR: While executing gem ... (Errno::EACCES)
Permission denied - /home/username/.gem
Usually when I install gems as root, it knows to install it into /usr/lib/ruby/gems, so why is it checking my home directory at all? Another quirk is when I do gem install rack (not as root), it says:
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions into the /usr/lib/ruby/gems/1.8 directory.
which is where I want it to go. I've already tried clearing source_caches, trying different versions of RubyGems (1.3.5), forcing installation into /usr/lib with -i to no avail. Any ideas on why RubyGems is so insistent on checking my /home directory when installing as root?
Sounds like it could be a path issue coupled with having multiple versions installed.
Any difference in output between:
sudo gem env
and
gem env
Try running:
gem environment
and checking the values for the GEM PATH. More info at http://docs.rubygems.org/read/chapter/10#page31
I was running into the same problem myself on Fedora 15, so I ran 'gem install' with the '--backtrace' option to see what was going on.
It turned out it was failing at /usr/lib/ruby/site_ruby/1.8/rubygems/doc_manager.rb:203 where it tried to chdir to the directory it had previously stored (the home directory of the user I was running sudo as)
I didn't extensively debug to see what the underlying cause was, just rather used a quick workaround so I could continue moving forward. The workaround was simply to cd to the root directory, eg cd /, before running the gem install command.
Hope this helps / solves your issue.
Woulda been easier to su (password) then chmod 755 /usr/lib/ruby/gems/1.8