Where should i put my rubygems after installation? - ruby

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.

Related

rubygem is installed but now in LOCAL GEMs database

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.

Install gem in local folder

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.

When installing a gem, should only the library get installed, or should the executable get installed as well?

I have installed RSpec with the gem (gem install rspec) command. Everything went ok. If I try to reinstall it again, I get a message like it has already been installed.
When I try to use rspec from the command line on Ubuntu, the terminal can't find the program.
My question is does the gem command only install the libraries, meaning I need to manually install the rspec executable myself, or is the gem command supposed to install everything, which would mean something went wrong during the install?
I have confirmed that the executable does get installed and should be able to run on it's own.
You can verify that the gem is installed by checking the list of installed gem using : gem query.
You can also check the paths used by gem using: gem env.
This should give you the path to the Ruby version the gems are using, their executable path (so you can update your path) and where they are stored.
Make sure they are configured to use the correct Ruby version (if you use more than one) and the path is in you $PATH variable.

Can't install JSON gem

I need to install json because I get this error:
Could not find json-1.4.6 in any of the sources
I ran gem install json and bundle install but I was only able to install json-1.5.1 when I need json-1.4.6
I have gem 'json', '1.4.6' in my gemfile, so I'm not sure what's going on...
UPDATE
I get this error:
Installing json (1.4.6) /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/fileutils.rb:1216:in `chmod': Operation not permitted - /Library/Ruby/Gems/1.8/gems/json-1.4.6/CHANGES (Errno::EPERM)
After checking logs by running $ heroku logs
I found "An error occurred while installing json (1.4.6), and Bundler cannot continue.
Make sure that gem install json -v '1.4.6' succeeds before bundling."
I then removed 2 json entries from the Gemfile.lock and had no further issues.
Why did you run gem install json at all? Bundler takes care of that for you and will ensure that the correct version of each gem is installed (since sometimes dependencies require an older version). Run
gem uninstall json
bundle install
Also ensure you have source 'https://rubygems.org' at the top of your Gemfile.
As for the permissions info, you may have to run gem and bundle commands with sudo.
By the way, I highly recommend taking a look at and using RVM, particularly the gemsets feature. It will make your life infinitely better when developing Ruby apps. If you decide to do so, I'd also suggest trashing all the gems you've install using the system Ruby by running sudo rm -rf /Library/Ruby/Gems/1.8/. It's also important that when using RVM you don't have to use sudo when running gem (or bundle), which is not only safer but less typing too.
Please update your rubygems by executing the following command..
gem update --system
may be it will solve the problem. After updating your gem. Then run the following command to install json
gem install json
Now you can get json gem installed in your system.
Try:
$ sudo apt-get install ruby1.8-dev
If you're using rbenv, try rbenv rehash
I had this problem when trying to build a website with Jekyll.
Turned out I hadn't followed all the instructions at https://jekyllrb.com/docs/installation/ubuntu/
I don't know if it was the missing packages or commands into ~/.bashrc but it fixed the problem in two instances of Ubuntu in WSL
Remove the json entries from the Gemfile.lock file and try to re run bundle install..

ruby 1.9.2 installation and gems

I have installed Ruby 1.9.2 from source. But it seems there is some trouble recognizing the bundler gem which I have already installed.
My /etc/environment file:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/ruby/bin"
It looks like my gems are in /usr/local/ruby/gems/1.9.1/gems/.
In my rails application when I attempt to run sudo bundle install I get an error:
sudo: bundle: command not found
Also, why do the directories say 1.9.1?
Type which ruby to see the path your system thinks ruby is in.
Did you use a --prefix=... option for configure when you set up the configuration? Normally Ruby from source wouldn't be in /usr/local/ruby/bin. The Ruby executable would be in /usr/local/bin/ruby, but that is not how you'd set up your PATH to use it, so that looks suspicious. Notice that your path already contains /usr/local/bin so if Ruby installed into the normal location for a source-installation, that path will pick it up and your final search of /usr/local/bin/ruby will be wrong and unnecessary.
If you installed the gem before you installed the new version of Ruby then the gem would be part of the previous installation, not the current one, and wouldn't be visible to it. They're separate installs.
Unless you are trying to do a system-wide install for multiple users there is no real reason to compile from source and allow it to install to /usr/local/bin. I highly recommend installing RVM, then letting it install any Ruby versions into RVM's ~/.rvm sandbox. Gems will also be installed relative to the currently enabled RVM controlled ruby, which is a really good thing.

Resources