Ruby Gems returns "command not found"
Asked Answered
H

5

23

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?

Hackler answered 6/3, 2010 at 11:22 Comment(0)
R
36

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.

Ratter answered 6/3, 2010 at 13:53 Comment(3)
ahh i was presuming that if i added /adam/.gem/ to the path then its subdirectories would automatically searched as well. dumb of me. thanks for thatHackler
Note that on some versions of Ubuntu, the 1.8 gem bin path can be found at /var/lib/gems/1.8/bin. This command is also handy for adding the sudo path to your bash profile echo -e '\nexport PATH=$PATH:/var/lib/gems/1.8/bin' >>~/.bashrcSweptwing
You can find the exact patch by running "gem environment". The EXECUTABLE DIRECTORY is the line you need.Shipentine
C
14

(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.

Culinary answered 3/4, 2017 at 14:32 Comment(1)
At last! Thank you for your theft :)Succinic
C
3

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
Conglobate answered 9/7, 2013 at 2:48 Comment(0)
H
0

it happened to macOS Ventura 13.6.1,

and it works, when i add

export PATH="/usr/local/lib/ruby/gems/3.3.0/bin:$PATH"

in .zshrc file

  • 3.3.0 is your gem version
Hiltan answered 15/1 at 7:42 Comment(0)
T
0

I had the same issue when I installed that via Conda on a server. In this case, you cannot find it in the mentioned paths, it should be within the ".conda" folder in the home user folder. for example:

/home/YOURUSER/.conda/envs/YOURENVIRONMENT/bin

in this case, replace this path (after the replacement action of capital letters with your real folder names):

export PATH=$PATH:/home/YOURUSER/.conda/envs/YOURENVIRONMENT/bin

and accordingly, you can put it in ".bashrc" file to be executed automatically after any session initiation (add that line at the end of the bashrc file for example). You can find this file in the home directory of your user.

Teens answered 2/4 at 1:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.