Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby Gems returns "command not found"

Tags:

ruby

rubygems

Ubuntu 9.10

Just installed newgem

gem install newgem

and when i try

newgem new_project

I get

adam@adam-ubuntu:~$ newgem newproject
newgem: command not found

Ive checked my path via echo $PATH

adam@adam-ubuntu:~$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/adam/.gem

and my gem enviroment

adam@adam-ubuntu:~$ gem environment
RubyGems Environment:
  - RUBYGEMS VERSION: 1.3.6
  - RUBY VERSION: 1.8.7 (2009-06-12 patchlevel 174) [x86_64-linux]
  - INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.8
  - RUBY EXECUTABLE: /usr/bin/ruby1.8
  - EXECUTABLE DIRECTORY: /usr/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /usr/lib/ruby/gems/1.8
     - /home/adam/.gem/ruby/1.8
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://rubygems.org/

Im not hot with paths etc but all the gem directories listed above are on the path so how come it cant find the command?

like image 566
robodisco Avatar asked Mar 06 '10 11:03

robodisco


3 Answers

Your $PATH variable needs to include the exact path to your Ruby's bin directory. Adding a directory to the PATH does not include it's subfolders. Try adding the bin directory via:

export PATH=$PATH:/home/adam/.gem/ruby/1.8/bin 

or if you installed the gem using sudo:

export PATH=$PATH:/usr/lib/ruby/gems/1.8/bin 

You might want to add this to your .bashrc file, so that you don't have to set this manually every time your open up a new bash.

like image 135
rubiii Avatar answered Sep 22 '22 05:09

rubiii


(Just stealing @John Franklin's comment)

$ gem environment 

Will tell you the EXECUTABLE DIRECTORY. Then put whatever that value is in your PATH like so (in your .bashrc or other shell config file).

export PATH="$PATH:/path/to/bin" 

Reload your shell and you should then be able to use the installed gem.

like image 30
Niels Bom Avatar answered Sep 25 '22 05:09

Niels Bom


If you use RVM (most do), then it will take care of this for you. In fact putting it in your path directly may conflict. You have to set a ruby to use though. Run one of these on the command line.

rvm use 1.9.3

or

rvm use --default 1.9.3
like image 35
vish Avatar answered Sep 22 '22 05:09

vish