I have a RedHat 7 system and I have installed the ruby 2.0.0.648 and rubygem 2.0.14 package and it has also installed a few dependent gems.
My problem is when I run the
gem list command I don't see any of the gems.
If I cd into the /usr/share/gems/gems/ directory I can see all of the files.
My question is…
How can I force the “gems command” to scan the /usr/share/gems/gems directory and update the
*** LOCAL GEMS *** database?
There has to be a way to manually edit the files to tell the gems command that all of the files are really on the system.
You can change the path to your gems by running the following command in your shell (or by adding it to your shell profile and reloading your shell):
export GEM_PATH=/usr/share/gems/gems
After running this command you can verify that the change has taken effect by running gem env:
RubyGems Environment:
<snipped>
- GEM PATHS:
- /usr/share/gems/gems
<snipped>
It sounds like you are not installing additional gems since your system is not connected to the Internet, but if you were to use the gem install command then you would also want to set GEM_HOME to the same path:
export GEM_HOME=/usr/share/gems/gems
GEM_PATH is where gem and bundler will find gems and GEM_HOME is where gems will be installed.
More details here and here.
Related
I have limited privileges on a shared machine I'm using, so I can't install gems the way I'm used to. For example:
$ gem install request-log-analyzer
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions into the /usr/lib/ruby/gems/1.8 directory.
Is it possible to install a gem locally? (if it matters, I'm trying to install this gem.)
I saw a number of posts on Stack Overflow that talked about using Bundler or gemfiles but I'm not installing this gem for a Ruby on Rails project - I just want to use it in isolation.
I'm running Linux, not sure which flavor though.
You can try:
gem install --user-install gem_name
Add the --local flag to your install:
gem install --local request-log-analyzer
If that causes any problems, try downloading the gem manually and pointing gem directly to it using:
gem install --local path/to/gem/filename.gem
If you want to install it to your user home, as per rubygems:
When you use the --user-install option, RubyGems will install the gems
to a directory inside your home directory, something like
~/.gem/ruby/1.9.1. The commands provided by the gems you installed
will end up in ~/.gem/ruby/1.9.1/bin. For the programs installed there
to be available for you, you need to add ~/.gem/ruby/1.9.1/bin to your
PATH environment variable.
The command for this would just be
gem install --user-install request-log-analyzer
You could just use RVM: Ruby Version Manager. It is a complete version manager, along the lines of node version manager (nvm) and others, in that it allows you to have different versions of ruby and different collections of gems for each project. It does the job of keeping gems isolated from each other as well as from the system ruby, but at the expense of learning a complete version manager.
When run without root, it installs locally in ~/.rvm and doesn't affect other users.
I seem to be constantly having problems with getting the gems in the right place (and not needing to use sudo when installing them.)
To address the sudo issue, I installed rbenv and then use that to install ruby 2.1.0 so that I had a separate one from Mac OSX system.
Then I installed bundler. But when I install gems from a Gemfile with bundler, I cannot find them.
Between all the steps I have taken, such as adding lines to my .bash_profile and so forth, I have the following, but really just want a clear, straightforward way to manage gems and their local execution:
gem env :
Edit: I removed everything and reset PATH -- still didn't fix anything, but you can see that gems are installed in one directory but when I call the executable, the command cannot be found:
RubyGems Environment:
- RUBYGEMS VERSION: 2.0.14
- RUBY VERSION: 2.0.0 (2014-02-24 patchlevel 451) [universal.x86_64-darwin13]
- INSTALLATION DIRECTORY: /Library/Ruby/Gems/2.0.0
- RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
- EXECUTABLE DIRECTORY: /usr/bin
- RUBYGEMS PLATFORMS:
- ruby
- universal-darwin-13
- GEM PATHS:
- /Library/Ruby/Gems/2.0.0
- /Users/fongster/.gem/ruby/2.0.0
- /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/gems/2.0.0
Here is what happens when I want to run, say shotgun:
bash-3.2$ shotgun
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/dependency.rb:296:into_specs': Could not find 'shotgun' (>= 0) among 12 total gem(s) (Gem::LoadError)
Can someone point me to simple, straightforward directdions for ruby gem management on OSX so that:
I don't need to use sudo to install gems
I can use bundler to install from a Gemfile for a given project
Those gems and their executables (shotgun, restclient, sass) can just be executed
My local environment based on this set up 'just works' in heroku?
I don't need to type bundle exec when I need to do stuff
Also some clarity on whether I need to always go to a bash shell (currently, I have been using exec bash to get my shell working).
EDIT: Following the steps below and have this response upon bundle:
Errno::EEXIST: File exists # dir_s_mkdir - /Users/fongster/.rbenv/shims/gem
An error occurred while installing backports (3.6.3), and Bundler cannot
continue.
Make sure that `gem install backports -v '3.6.3'` succeeds before bundling.
Use rbenv-gemset. It works great and meets all your requirements. I have been using it for 2 years and have not had any problems. No issues with Heroku.
Here's my process for setting up a new Ruby project:
1. Create directory (or Rails app in new directory)
2. cd directory
3. Set ruby version: Use 2.1.0 or another version
rbenv local 2.1.0
4. Set gemset: replace app-name with the name of the app
echo app-name > .rbenv-gemsets
5. Check gemset. Should be app-name global:
rbenv gemset active
6. rbenv rehash
7. Create Gemfile
8. gem install bundler
9. bundle
When it does not work as expected, do rbenv rehash.
You should never need to install gems using sudo.
Regarding your shell, that could be causing problems. If a regular terminal doesn't work then there is probably another issue.
Since the issue seems related to your shell and PATH, here's my .bash_profile
export PATH="$HOME/.rbenv/bin:$PATH"
export PATH=/usr/local/bin:$PATH
eval "$(rbenv init -)"
You may want to try replacing your .bash_profile with the above, or create a new user and see if the issue disappears.
From a clean start
You do not have to do anything apart from the plain steps stated on the Bundler home page:
Do NOT use sudo bundle ...
Do NOT change anything to your PATH
Do not touch any ~/.file
Copy require 'bundler/setup' at the top of your first application file
DO use bundle exec in front of all your Bundler-managed "binaries"
Everything just works using the nice defaults for a developer workstation. When you want to go further like running multiples Rubies side by side or deploying to prod or are fed up with typing bundle exec (which you should alias to bex using alias bex='bundle exec') you can then Read The Full Manual, type bundle install --binstubs and install one of the Rubymongers (RBEnv, RVM).
In your specific situation
I would restart from scratch:
uninstall RBEnv (rm -rf ~/.rbenv and delete rbenv mentions in grep rbenv ~/.bashrc ~/.bash_profile ~/.zshrc /etc/profile /etc/profile.d/*)
uninstall Bundler
I am using Ubuntu 12.10 and I am trying to get my project up and running using rbenv and bundler.
I have successfully installed rbenv from the apt repository and installed the required version of ruby using ruby-build.
When I run which gem I get the global /usr/bin/gem that I assume came with the apt repository install. However when I run rbenv which gem I get the proper local gem /home/kasuko/.rbenv/versions/1.9.2-p290/bin/gem
However when I run gem install bundler I get an error on permissions with "Permission denied - /var/lib/gems" which leads me to believe that it is using the global gem.
So when I run /home/kasuko/.rbenv/versions/1.9.2-p290/bin/gem install bundler it successfully installs bundler
I do have the rbenv init line in my ~/.zshrc.local (which is sourced in my ~/.zshrc) and I get the updated path "/home/kasuko/.rbenv/shims:/home/kasuko/.bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games" so I'm pretty sure it's installed correctly.
So why aren't my rbenv shims being used?
Thanks
Kasuko
If you're not sure which gem is being executed, try gem env which will show you useful information about the version of gem you're running, such as the rubygems version, corresponding ruby executable, gem paths and other good stuff.
Your PATH seems correct. Try running hash -r to clear the shell's cache of executable paths just in case.
Once you've done this, which gem should give you /home/kasuko/.rbenv/shims/gem, which would indicate that it's deferring to rbenv to determine the actual executable to run.
You may then need to run rbenv rehash. This should be run every time you install a new gem with an executable (like bundler, rake, etc). It will update all the shims to point to the correct executables.
I'm running Ubuntu 10.04 and originally installed ruby 1.9.1 (from source). I've just decided to try out ruby 1.9.2 and rails 3, and it seemed like a good time to use rvm to deal with the multiple ruby installs and gemsets.
rvm installed and seems to be working, I installed ruby 1.9.2 in rvm and made that my default ruby. However, every time I try to install a gem under ruby 1.9.2 I see this error.
mark#Steve-Austins-Penguin:~$ gem install haml
ERROR: While executing gem ... (Errno::EACCES)
Permission denied - /home/mark/.gem/specs
gem environment returns:
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.7
- RUBY VERSION: 1.9.2 (2010-08-18 patchlevel 0) [x86_64-linux]
- INSTALLATION DIRECTORY: /home/mark/.rvm/gems/ruby-1.9.2-p0
- RUBY EXECUTABLE: /home/mark/.rvm/rubies/ruby-1.9.2-p0/bin/ruby
- EXECUTABLE DIRECTORY: /home/mark/.rvm/gems/ruby-1.9.2-p0/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /home/mark/.rvm/gems/ruby-1.9.2-p0
- /home/mark/.rvm/gems/ruby-1.9.2-p0#global
<snip>
But if the correct installation, ruby and gem paths are showing here why is ruby trying to install gems to /home/mark/.gem? All the variables and paths shown by env look right, and I can't find a .gemrc file anywhere on my system that might contain conflicting path settings.
So I guess my question is what might be causing rubygems to attempt to install to /home/mark/.gems instead of the correct paths set by rvm?
In response to the question below:
mark#Steve-Austins-Penguin:~$ echo $PATH
/home/mark/.rvm/gems/ruby-1.9.2-p0/bin:/home/mark/.rvm/gems/ruby-1.9.2-p0#global/bin:/home/mark/.rvm/rubies/ruby-1.9.2-p0/bin:/home/mark/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
mark#Steve-Austins-Penguin:~$ which gem
/home/mark/.rvm/rubies/ruby-1.9.2-p0/bin/gem
mark#Steve-Austins-Penguin:~$ rvm list
rvm rubies
ruby-1.8.7-p302 [ x86_64 ]
=> ruby-1.9.2-p0 [ x86_64 ]
mark#Steve-Austins-Penguin:~$ env
rvm_gemsets_path=/home/mark/.rvm/gemsets
MANPATH=:/home/mark/.rvm/man
rvm_scripts_path=/home/mark/.rvm/scripts
rvm_bin_path=/home/mark/.rvm/bin
GEM_HOME=/home/mark/.rvm/gems/ruby-1.9.2-p0
rvm_patchsets_path=/home/mark/.rvm/patchsets
SHELL=/bin/bash
IRBRC=/home/mark/.rvm/rubies/ruby-1.9.2-p0/.irbrc
rvm_patches_path=/home/mark/.rvm/patches
MY_RUBY_HOME=/home/mark/.rvm/rubies/ruby-1.9.2-p0
rvm_selfcontained=1
USER=mark
__shell_array_start=0
rvm_gems_cache_path=/home/mark/.rvm/gems/cache
rvm_config_path=/home/mark/.rvm/config
rvm_path=/home/mark/.rvm
USERNAME=mark
rvm_gemset_separator=#
rvm_ruby_args=
rvm_rubies_path=/home/mark/.rvm/rubies
PWD=/home/mark
rvm_hooks_path=/home/mark/.rvm/hooks
rvm_version=1.0.1
rvm_src_path=/home/mark/.rvm/src
HOME=/home/mark
rvm_gems_path=/home/mark/.rvm/gems
rvm_ruby_string=ruby-1.9.2-p0
BUNDLE_PATH=/home/mark/.rvm/gems/ruby-1.9.2-p0
rvm_tmp_path=/home/mark/.rvm/tmp
LOGNAME=mark
GEM_PATH=/home/mark/.rvm/gems/ruby-1.9.2-p0:/home/mark/.rvm/gems/ruby-1.9.2-p0#global
rvm_action=list
rvm_log_path=/home/mark/.rvm/log
rvm_interactive=1
RUBY_VERSION=ruby-1.9.2-p0
rvm_archives_path=/home/mark/.rvm/archives
rvm_repo_path=/home/mark/.rvm/repos
_=/usr/bin/env
Note that I've edited down the response from env slightly - simply to keep the size of this post under control - by removing all the entries relating to X, GNOME and SSH.
Following up the backtrace from running gem install -V --backtrace --debug haml (thanks zzzhc) and taking a closer look at the /home/mark/.gem directory I found that there were no gems installed there, just gemspec files and gem source files. In the spirit of experimentation I deleted /home/mark/.gem and re ran the gem install command and suddenly it was working. And that it had recreated /home/mark/.gem containing gemspecs for the gems I'd just installed.
It's clear now that I'd misinterpreted the error message in the original question; rubygems didn't fail while trying to install gems to /home/mark/.gem, it was simply using that directory as a temporary store for the gemspecs of newly downloaded gems about to be installed. Before installing rvm I'd been installing gems onto the system using sudo gem install... which would have created the /home/mark/.gem directory with root permissions. So rubygems run without sudo was unable to access the temp directory to store gemspecs in and was aborting before it could install the gems. Doh!
Another way is type which gem after getting into the ruby version. You will get something like this - /home/username/.rvm/rubies/ruby-1.9.2-p180/bin/gem. Now just type sudo /home/username/.rvm/rubies/ruby-1.9.2-p180/bin/gem install gem_name.
Specifying the complete path and adding sudo work fine.
check the first line of /home/mark/.rvm/rubies/ruby-1.9.2-p0/bin/gem and look at http://yehudakatz.com/2010/08/24/a-tale-of-abort-traps-or-always-question-your-assumptions/
Suppose I installed some ruby gems using gem install gemname. Where should I install them, and when what directory should I run gem install rubygems-update-1.3.1.gem from?
gem env
will tell you where they were installed.
In general on windows it doesn't matter what directory you're in, running
gem update --system
will work from anywhere.
-r
They are automatically installed to your GEM_HOME. In Linux, you can open a terminal and type:
echo $GEM_HOME
To find out where that is exactly.
Is the place where you view your all gems list for linux.
/usr/lib/ruby/gems
You shouldn't need to be in any specific directory; running gem install will put the gem in the directory that gem expects your gems to be.
As mentioned in other answers, if you want to see where that directory is, run gem env and take a look at the INSTALLATION DIRECTORY: line.