I have $GEM_HOME set, but gem install is still installing to the default ~/.gem directory.
This rubygems issue says to remove the --user-install option in .gemrc, but I don't have a .gemrc file.
How can I get gem install to honour the value of $GEM_HOME?
Here I firstly remove ~/.gem, and then show that it is automatically created:
% rm -rf ~/.gem
% find ~ -name '*gemrc*'
% # No output, so .gemrc doesn't exist
% echo $GEM_HOME
/home/ravi/.local/share/gem
% gem install neovim
Building native extensions. This could take a while...
Successfully installed msgpack-1.2.7
Successfully installed multi_json-1.13.1
Successfully installed neovim-0.8.0
Parsing documentation for msgpack-1.2.7
Installing ri documentation for msgpack-1.2.7
Parsing documentation for multi_json-1.13.1
Installing ri documentation for multi_json-1.13.1
Parsing documentation for neovim-0.8.0
Installing ri documentation for neovim-0.8.0
Done installing documentation for msgpack, multi_json, neovim after 0 seconds
3 gems installed
% ls -ld ~/.gem
drwxr-xr-x 1 ravi ravi 8 Mar 9 12:34 /home/ravi/.gem/
Environment information:
% gem --version
3.0.2
% gem env
RubyGems Environment:
- RUBYGEMS VERSION: 3.0.2
- RUBY VERSION: 2.6.1 (2019-01-30 patchlevel 33) [x86_64-linux]
- INSTALLATION DIRECTORY: /home/ravi/.local/share/gem
- USER INSTALLATION DIRECTORY: /home/ravi/.gem/ruby/2.6.0
- RUBY EXECUTABLE: /usr/bin/ruby
- GIT EXECUTABLE: /usr/bin/git
- EXECUTABLE DIRECTORY: /home/ravi/.local/share/gem/bin
- SPEC CACHE DIRECTORY: /home/ravi/.cache/gem
- SYSTEM CONFIGURATION DIRECTORY: /etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /home/ravi/.local/share/gem
- /usr/lib/ruby/gems/2.6.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- "gem" => "--user-install"
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /home/ravi/.gem/ruby/2.6.0/bin
- /home/ravi/bin
- /home/ravi/.local/share/npm/bin
- /home/ravi/.local/share/go/bin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/local/sbin
- /usr/lib/jvm/default/bin
- /usr/bin/site_perl
- /usr/bin/vendor_perl
- /usr/bin/core_perl
- /usr/lib/systemd
- /home/ravi/.local/share/miniconda3/bin
- /home/ravi/.cabal/bin
- /usr/lib/jvm/default/bin
- /usr/bin/site_perl
- /usr/bin/vendor_perl
- /usr/bin/core_perl
%
I had the same problem with rubygems installed with snap (Ubuntu Software), which installs to ~/.gem by default. I was able to change the install directory by using --install-dir switch
$ gem install --install-dir /path/to/custom/directory foo
However, I later had problems using the gems which I installed in a non-default directory.
Uninstalling it and installing with apt solved all problems.
$ sudo snap remove ruby
$ sudo apt-get install rubygems
Now, gems are always installed to $GEM_HOME. In order to still have ~/.gem as default install location, add this to your init script (e.g. ~/.bashrc):
export GEM_HOME=$HOME/.gem
export PATH=$PATH:$GEM_HOME/bin
To overwrite the install location, you just have to overwrite GEM_HOME before calling gem install.
As Casper pointed out in the comment, my configuration was still getting --user-install from somewhere.
While my ~/.gemrc didn't exist, I checked in /etc/gemrc and found the following:
# --user-install is used to install to $HOME/.gem/ by default since we want to separate # pacman installed gems and gem installed gems install: --user-install
To override this, I added to my ~/.gemrc:
install: --no-user-install
And now $GEM_HOME is respected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With