noob - unable to run gem via terminal

fookh's Avatar


04 Jan, 2019 06:09 AM

Hello -

A version of this problem is posted on StackOverflow, as well, but remains unsolved there. I have included 2 screenshots to hopefully clear up any confusion.

I uploaded my first gem into rubygems. The code is tested and the gemspec is fine. It is in rubygems and rubydoc. I installed it on my machine via gem install [mygem]. gem list lists it. However [mygem] command yields mygem: command not found. This is also shown in Screenshot 1

require '[mygem]' works flawlessly in IRB. It runs smoothly (interacts with user). Once finished, it returns true. When I require other gems, eg require '[another_gem]' true is returned immediately. The code doesn't actually run. This is screenshot 2

Aside I could've sworn when I first published I played with it and [mygem] worked flawlessly to run my gem...

what can I do to diagnose this problem? Please advise. Hopefully there is a simple solution to this and maybe we'll get a good discussion going ;) .

  1. Support Staff 1 Posted by sonalkr132 on 04 Jan, 2019 07:23 AM

    sonalkr132's Avatar
  2. Support Staff 2 Posted by sonalkr132 on 04 Jan, 2019 07:24 AM

    sonalkr132's Avatar


    Basically, find out the bin directory of installed gems and add it your $PATH. Check gem env.

  3. 3 Posted by fookh on 04 Jan, 2019 02:16 PM

    fookh's Avatar

    thank you the reply. /usr/local/bin and ./sbin are both in my $PATH and also in the shell path. Attached another screenshot showing this.

    Please advise? there must be something simple I'm missing here ;(

  4. Support Staff 4 Posted by sonalkr132 on 04 Jan, 2019 02:25 PM

    sonalkr132's Avatar

    You can see INSTALLATION DIRECTORY is /var/lib/gems/2.3.0. Check if mygem is present in /var/lib/gems/2.3.0/bin. If yes, you only need to run:
    export PATH="$PATH:/var/lib/gems/2.3.0/bin"

  5. 5 Posted by fookh on 05 Jan, 2019 12:43 AM

    fookh's Avatar

    Hi -

    Apologies for these late replies. I followed your instructions, essentially adding ../bin to my $PATH. Unfortunately it proved unsuccessful. I have attached another screenshot, showing this.

  6. 6 Posted by fookh on 05 Jan, 2019 01:30 AM

    fookh's Avatar

    Apologies: [mygem] is not in /var/lib/gems/2.3.0/bin. (But it is in /var/lib/gems/2.3.0/gems ) Should I edit my .~/.bashrc file to include /var/lib/gems/2.3.0/bin?

    However, FYI none of my other installed gems are in ../bin and they work off my terminal ok.

  7. Support Staff 7 Posted by kerrizor on 05 Jan, 2019 04:52 PM

    kerrizor's Avatar

    What does your gemspec look like?

  8. 8 Posted by fookh on 05 Jan, 2019 11:49 PM

    fookh's Avatar

    pretty standard. No problems in the building the gem with gem build [gem.gemspec]. I also published without problem, with gem push [gem-ver_num.gem] .

    Full disclosure, I deleted the gem from my computer and did gem install [mygem] in the attempt to diagnose the problem. So I retyped the gemspec from memory.

    Again: require '[mygem]' in irb works...

  9. Support Staff 9 Posted by kerrizor on 06 Jan, 2019 07:59 PM

    kerrizor's Avatar

    I'm guessing it might be that you're missing a gem.executables declaration in your gemspec.. here's a link to our docs on building gems with command-line executables.. hopefully that'll get you pointed in the right direction, and give you some other avenues to explore!

  10. kerrizor closed this discussion on 06 Jan, 2019 07:59 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac