rvmsudo gem install capistrano - ruby

When running
rvmsudo gem install capistrano
I get this warning:
Warning: can not check `/etc/sudoers` for `secure_path`, falling back to call via `/usr/bin/env`, this breaks rules from `/etc/sudoers`. Run:
export rvmsudo_secure_path=1
to avoid the warning, put it in shell initialization file to make it persistent.
In case there is no `secure_path` in `/etc/sudoers`. Run:
export rvmsudo_secure_path=0
to avoid the warning, put it in shell initialization file to make it persistent.
I'm on Mac OS X and I've got no secure_path in /etc/sudoers so I assume I need to put:
export rvmsudo_secure_path=0
in my .bash_profile, right?

Yes, based on the RVM warning, your .bash_profile is the correct place to put that export line.
Aside from that issue though, is using rvmsudo necessary? If you are using RVM you should be able to install gems without sudo (because they are installing into your home directory, or a user writable system directory).

Related

Error sudo: gem: command not found

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.

RVM warning when installing Passenger on the Mac

Installing Passenger on the Mac runs into this problem.
Any suggestions?
sudo passenger-install-apache2-module
...
* Checking for Zlib development headers...
Found: yes
Location: /usr/local/include/zlib.h
Your RVM wrapper scripts are too old, or some wrapper scripts are missing. Please update/regenerate them first by running:
rvmsudo rvm get stable && rvm reload && rvmsudo rvm repair all
If that doesn't seem to work, please run:
rvmsudo rvm wrapper [] --no-prefix --all
First I did:
$ rvmsudo rvm get stable && rvm reload && rvmsudo rvm repair all
Warning: can not check `/etc/sudoers` for `secure_path`, falling back to call via `/usr/bin/env`, this breaks rules from `/etc/sudoers`. export rvmsudo_secure_path=1 to avoid the warning.
which re-installed rvm and then I did:
$ rvmsudo rvm wrapper [] --no-prefix --all
Warning: can not check `/etc/sudoers` for `secure_path`, falling back to call via `/usr/bin/env`, this breaks rules from `/etc/sudoers`. Run:
export rvmsudo_secure_path=1
to avoid the warning, put it in shell initialization file to make it persistent.
In case there is no `secure_path` in `/etc/sudoers`. Run:
export rvmsudo_secure_path=0
to avoid the warning, put it in shell initialization file to make it persistent.
awk: nonterminated character class ^[]=
source line number 1
context is
>>> /^[]=/ <<<
sed: 1: "s#^[]=##
": unbalanced brackets ([])
Unknown ruby interpreter string component: '[]'.
Could not load ruby [].
Add to your ~/.profile or ~/.bash_profile
export rvmsudo_secure_path=0
You may try to install passenger without sudo.
$ passenger-install-apache2-module

Not able to install a gem file?

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.

Error installing AWS SDK for Ruby on Mac

I'm learning Ruby to access an AWS SDB created by my partner. When I installed the AWS SDK for Ruby on my Mac, I got the following message:
WARNING: Installing to ~/.gem since /Library/Ruby/Gems/1.8 and
/usr/bin aren't both writable.
WARNING: You don't have /Users/royclymer/.gem/ruby/1.8/bin in your PATH,
gem executables will not run.
I'm familiar with "PATH" from my PC days but have just started using Terminal on the Mac (to run Ruby) and can't find PATH command there. Maybe this isn't a problem, because it did say "six gems installed" but I also got several statements like "No definition for get_options."
Thanks.
It sounds like you are trying to install a gem into your system install ruby. You can likely resolve this issue by prefixing the gem install command with sudo.
sudo gem install aws-sdk
While this should work, its generally better to use a different solution that does not require installing gems as root (try googling rvm and rbenv).
PATH is not a command, it's an environment variable. To see the current content, do echo $PATH in your terminal. To temporarily change your PATH you can just re-export it like so:
export PATH=~/.gem:$PATH
For a permanent change you may want to read up on .bash_profile or .bashrc as well as /etc/paths and /etc/paths.d/.

Installing Ruby gems not working with Home Brew

The gems I install via sudo gem install ... can't be executed (I get a command not found).
They seem to install into /usr/local/Cellar/ which is Brew's install directory (also, the gems in /Library/Ruby/ don't work either). Is there anything else I need to do to make the gems executable? I'm using ZSH on Mac OS X 10.6 with Ruby v1.8 for the one in Brew.
EDIT: It seems to be working now. I just went out for a few hours and came back to try it again.
Homebrew is nice. However unlike brew and npm, gem does not make aliases in /usr/local/bin automatically.
Solution
I went for a very simple approach (as of March 2020):
# Based on "`brew --prefix ruby`/bin"
export PATH=/usr/local/opt/ruby/bin:$PATH
# Based on "`gem environment gemdir`/bin"
export PATH=/usr/local/lib/ruby/gems/3.0.0/bin:$PATH
Add this to your .bashrc (or .bash_profile, .zshrc, etc.).
That's it! Now all Ruby bins and installed gems will be available from your shell!
In older versions of Homebrew (before 2017), there was a separate package for Ruby 2 called ruby20, for which you'd use the following snippet instead:
export PATH=/usr/local/opt/ruby20/bin:$PATH
This line was the only line needed at the time. But, in Ruby 2.1 the gems got moved to a separate directory. No longer under /usr/local/opt/ruby/bin, but instead at /usr/local/lib/ruby/gems/2.0.0/bin (where "2.0.0" is the last major Ruby version for Gem's purposes).
How it works
Homebrew keeps track of where it installed a package, and maintains a symbolic link for you that points there.
$ brew --prefix ruby
/usr/local/opt/ruby
$ l /usr/local/opt/ruby
/usr/local/opt/ruby# -> ../Cellar/ruby/2.5.3_1
Effectively, adding /usr/local/opt/ruby to PATH is the same as the following:
export PATH=/usr/local/Cellar/ruby/2.5.3_1/bin:$PATH
Except, this long version hardcodes the currently installed version of Ruby and would stop working next time you upgrade Ruby.
As for Gem, the following command will tell you the exact directory Gem adds new packages to:
$ gem environment gemdir
/usr/local/lib/ruby/gems/2.7.0
Tools
These tools were meant to automatically bridge between Homebrew and Gem:
josh/brew-gem (no longer exists)
indirect/brewbygems (unmaintained)
I haven't used these but they might work for you.
brew unlink ruby; brew link ruby might add symlinks to /usr/local/bin/:
$ which sass
$ brew unlink ruby; brew link ruby
Unlinking /usr/local/Cellar/ruby/2.0.0-p0... 20 links removed
Linking /usr/local/Cellar/ruby/2.0.0-p0... 31 symlinks created
$ which sass
/usr/local/bin/sass
brew --prefix ruby is still pretty slow, but you could also just add /usr/local/opt/ruby/bin to the path.
$ time brew --prefix ruby
/usr/local/opt/ruby
0.216
$ time brew --prefix ruby
/usr/local/opt/ruby
0.076
$ stat -f%Y /usr/local/opt/ruby
../Cellar/ruby/2.0.0-p0
I like home brew. There's probably a better way to do this, but if you run:
gem environment
That will print out a nice list of all the relevant paths. Look for the one labeled EXECUTABLE DIRECTORY. That's the one you want to add to your path. In my case that's /usr/local/Cellar/ruby/1.9.3-p362/bin/ruby but I would imagine it would change with newer version of Ruby.
I'm using /bin/bash as my shell, but the process of adding it to your path should be pretty much the name.
I use TextWrangler (via the command line tools) to edit my .profile file. To do that, it's just:
edit ~/.profile
When your done, either close your terminal and open a new one, or run:
source ~/.profile
Using the info in Timo's answer, I've got this:
PATH=/usr/local/opt/ruby/bin:$PATH
GEMSDIR=$(gem environment gemdir)/bin
PATH=$GEMSDIR:$PATH
export PATH
Works for Homebrew, works for the separate gems directory, and doesn't hardcode a Ruby version.
You can be fine with ruby installed by homebrew too.. You just lack the functionality of custom gemsets with homebrew.
first do:
sudo nano /etc/paths
this will bring up nano editor,
then add the following to the paths:
/usr/local/Cellar/ruby/1.9.3-p194/bin
your version of ruby will probably vary.
Thats it. It should now detect your gems.
Oh, btw, you need to Ctrl+X > y > ENTER to save a file in nano.
Instead of using => $(cd $(which gem)/..; pwd)
You could use this instead => $(brew --prefix ruby)/bin
I think this evolve a bit.
Just add
export PATH=/usr/local/opt/ruby/bin:$PATH
To your .bashrc (or .bash_profile, .zshrc/.bashrc, .. – whatever you use).
If you have a problem with ruby itself
brew unlink ruby
brew link ruby

Resources