snap to install the latest version of
ruby under Ubuntu 16.04
$ sudo snap install ruby --classic $ which ruby /snap/bin/ruby $ ruby -v ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux]
Then I installed a ruby gem
pdfbeads (a PDF creation utility program)
sudo gem install pdfbeads
This command installs the utility in my home directory as
~/.gem/gems/pdfbeads-1.1.1/bin/pdfbeads. However, when I try to use this program within a shell script that converts DJVU files into PDF format, I get the following error message
djvu2pdf.sh: line 43: pdfbeads: command not found
ruby linked in
/snap/bin/ is in my
$PATH by default,
~/.gem/ is not. Here's the
gem environment after installation of
$ gem environment RubyGems Environment: - RUBYGEMS VERSION: 3.1.2 - RUBY VERSION: 2.7.0 (2019-12-25 patchlevel 0) [x86_64-linux] - INSTALLATION DIRECTORY: ~/.gem - USER INSTALLATION DIRECTORY: ~/.gem/ruby/2.7.0 - RUBY EXECUTABLE: /snap/bin/ruby - GIT EXECUTABLE: /usr/bin/git - EXECUTABLE DIRECTORY: ~/.gem/bin - SPEC CACHE DIRECTORY: ~/.gem/specs - SYSTEM CONFIGURATION DIRECTORY: //etc - RUBYGEMS PLATFORMS: - ruby - x86_64-linux - GEM PATHS: - ~/.gem - /snap/ruby/172/lib/ruby/gems/2.7.0 - GEM CONFIGURATION: - :update_sources => true - :verbose => true - :backtrace => false - :bulk_threshold => 1000 - REMOTE SOURCES: - https://rubygems.org/ - SHELL PATH: - /usr/local/sbin - /usr/local/bin - /usr/sbin - /usr/bin - /sbin - /bin - /usr/games - /usr/local/games - /snap/bin
I would have expected that the gem package installation should have taken care of the path issue, but that's not apparently the case -
pdfbeads is not in the execution directory path.
Clearly, I could add this one specific directory
~/.gem/gems/pdfbeads-1.1.1/bin/ to my
$PATH to solve this particular problem. However, as this is my first use of
ruby, I'm looking for a more general solution that would not require doing the same every time I install another ruby gem.
I've got a question for all the
ruby experts - is there some standard, more elegant way of resolving this issue that would also cover any future gem installations?