rubygems setup.rb: no such file of directory - ruby

I have a small question. When I tried to install rubygems by following the code here:
wget 'http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz'
tar -vxzf rubygems-1.3.5.tgz
cd rubygems-1.3.5
ruby setup.rb
But when I try to do ruby setup.rb it says bash: /usr/bin/ruby: No such file or directory
.
So I tried which ruby and it says /usr/local/bin/ruby
Any ideas how I can fix this path thing?

i got this to work,i had to update my path on /root and /home for this to work.
vim .bash_profile in root and home
replace PATH with
PATH=$PATH:$HOME/bin:/sbin:/usr/bin:/usr/local/bin
and it's working now

Related

Gem:File Permission Error Issue with gems (not duplicate)

I have been trying to install jekyll and bundler, and I keep getting this error:
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
I have tried so many things suggested by other posts. Ran rbenv, appended eval "$(rbenv init -)" to my bash_profile in order to run it automatically, did some stuff with sudo, and also tried installing using:
gem install jekyll --user-install
but then when I try to make a jekyll command the return is:
-bash: jekyll: no command found
I am at a loss. I know basically nothing about Unix and have been trying this for hours. Any thoughts?
P.S. Please do not mark as duplicate because other posts have not answered my question.
It seems you haven't add the user gem bin dir to the PATH.
ruby -rubygems -e 'puts Gem.user_dir'
this will show the gem user dir.
then add OUTPUT_FROM_LAST_CMD/bin to your path, or simply add
export PATH="$(ruby -rubygems -e 'puts Gem.user_dir')/bin":$PATH
to your ~/.bashrc
http://guides.rubygems.org/faqs/#user-install

jekyll installed but 'command not found'

I installed jekyll, but surprisingly somehow osx doesn't recognise its installed.
$ sudo gem install jekyll
Password:
Successfully installed jekyll-1.2.1
Parsing documentation for jekyll-1.2.1
Done installing documentation for jekyll after 1 seconds
1 gem installed
$ jekyll
-bash: jekyll: command not found
gem environment ( - INSTALLATION DIRECTORY: /usr/local/Cellar/ruby/2.0.0-p247/lib/ruby/gems/2.0.0 )
$ cd /usr/local/Cellar/ruby/2.0.0-p247/lib/ruby/gems/2.0.0/gems/
echo $PATH
/usr/local/bin:/usr/local/sbin:~/bin:/usr/local/bin:/usr/local/sbin:~/bin:/Users/TheSpiritMolecule/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/TheSpiritMolecule/.rvm/bin
I have rbenv installed and the step I missed was to do an rbenv rehash after gem install jekyll. The rehash creates a link in ~/.rbenv/shims which is in included in $PATH.
Okay I had to check what exatly does the $PATH means, and for what it is.
The problem was simple, somehow my ruby installion directory wasnt in my $path variable.
Useful links: Mac OS X: Set / Change $PATH Variable
Okay so here is the thing how I solved it:
echo "$PATH"
gem uninstall jekyll
find / -name jekyll (to delete if there is any leftovers somewhere )
gem environment ( get EXECUTABLE DIRECTORY path )
nano $HOME/.bash_profile ( go to the end of document and insert a new line )
export PATH="/usr/local/Cellar/ruby/2.0.0-p247/bin:$PATH"
you can do this on a templorary way by just writing it in terminal and not saving it in your .bash_profile
Following steps solved my problem
gem uninstall jekyll
sudo gem install jekyll
Open ~/.bash_profile and add this code in the last line,
export PATH=$PATH:/usr/local/lib/ruby/gems/1.9.1/gems/jekyll-2.5.2/bin
Save and close the .bash_profile
Close and reopen the mac terminal, try running jekyll now, it should work

Load Error on Ruby 1.9.3 Mountain Lion

I am new to Ruby and just installed Ruby 1.9.3. on my Moutnain Lion MacOSx with RVM and Homebrew.
After I installed Ruby, I wrote my first Tutorial Program (with text, textmate and Tincta) and saved it as a file.rb.
Now the problem is that i get this error message:
users-MacBook-Pro:~ user$ ruby calc.rb
ruby: No such file or directory -- calc.rb (LoadError)
The brew doctor command gives me this, but I don't even know if this has something to do with the issue:
Warning: /usr/bin occurs before /usr/local/bin
This means that system-provided programs will be used instead of those
provided by Homebrew. The following tools exist at both paths:
bashbug
gcov-4.2
git
git-cvsserver
git-receive-pack
git-shell
git-upload-archive
git-upload-pack
gitk
Consider amending your PATH so that /usr/local/bin
occurs before /usr/bin in your PATH.
Warning: Homebrew's sbin was not found in your path.
Consider amending your PATH variable so it contains:
/usr/local/sbin
Ruby is complaining that it can't find calc.rb. According to your description, you saved the file as file.rb, and then you tried to run calc.rb. Try ruby file.rb.
If that doesn't work, verify that ruby is working with
echo "puts 'hello'" | ruby
It should output hello. Then try running it from a file:
echo "puts 'hello'" > test.rb
ruby test.rb
A couple of things to troubleshoot from within your shell:
1 - Verify calc.rb exists:
ls calc.rb # will complain if calc.rb doesn't exist in the current directory
2 - Check where the ruby executable is being found:
which ruby # this might help narrow down issues with your $PATH
With regard to the homebrew issue, see if any of the following help:
brew doctor says “Error: /usr/bin occurs before /usr/local/bin” how to fix?
Where does $PATH get set in OS X 10.6 Snow Leopard? - still relevant in Mountain Lion AFAIK.

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.

Can "gem install" be configured to install executables outside /usr/bin/ by default?

By default, when you sudo gem install thegemname it will install executables into /usr/bin/
Is there a way to change this? For example, to install them into /usr/local/rubygems/bin (or any other path)?
The path doesn't seem to be hard-coded into the gemspec file, so I don't see why this shouldn't be possible (although I have very little experience with Ruby/Gems)
I'm adding this as an answer so that it is obvious when I run into this problem again :)
First, move all the bins in /var/lib/gems/1.8/bin/ to /usr/bin/. If you don't do this, then uninstalling or updating a gem will not remove the binary from the original bin directory.
You may also wish to remove the old path from $PATH
Next, edit ~/.gemrc and add (or update) the following line:
gem: --bindir /usr/bin
This overrides gem so that it always uses /usr/bin/ as the bin dir.
No need to update the path (especially messy for multiple-user machines).
See http://www.rubygems.org/read/chapter/11 and specify a ~/.gemrc which defines a gemhome variable.
For example:
gemhome: /usr/local/rubygems
You can also place this file in /etc/gemrc
Alternatively you can set the GEM_HOME env-variable:
$ export GEM_HOME=/tmp/gemtest
$ gem install bundler
$ ls /tmp/gemtest/bin/
bundle
Update (10 years later):
Andrey Rodionov below suggest using
gem: --bindir /usr/bin
On OS X, the executable directory is overridden to /usr/bin in the file /Library/Ruby/Site/1.8/rubygems/defaults.rb
# The default directory for binaries
def self.default_bindir
if defined? RUBY_FRAMEWORK_VERSION then # mac framework support
'/usr/bin'
else # generic install
ConfigMap[:bindir]
end
end
As a hackish work around, I changed /usr/bin to my desired bin location, which works correctly. There doesn't seem to be any way to override bindir from the ~/.gemrc config?
To install the executable to a desired directory, the command line option --bindir may be used:
sudo gem install thegemname --bindir /usr/local/rubygems/bin
Tried this option successfully with gem version 2.0.14.1.
For more command line options, run gem install --help on the command line.

Resources