Install gem in local folder - ruby

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.

Related

How to install a ruby gem from a git repository(using bundler) in the default gems folder rather than in a separate folder called bundler?

When I clone the repo of the gem and try installing using gem install <gem-name>, it gets installed to the default gems directory. But, when I try installing using bundler, it gets installed in a separate folder called 'bundler' which is not considered by GEM_PATH, as a result it is not usable in irb.
I want to install that gem like the other gems using bundler, but it should install in default gem folder, like the other gems. Any solution to this?
There's no direct way to install a gem(from git source) to the default location as bundler differentiates rubyorg gems and git source gems separately.
So I have managed to install that specific gem from Github using a third party gem called 'specific_install'. It fetches the source from the github repo itself and installs the gem.
To install specific_install:
gem install specific_install
gem 'specific_install' (in Gemfile)
Syntax:
gem specific_install <git repo SSH or HTTPS>

rbenv not using the shims Ubuntu 12.10

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.

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..

Where should i put my rubygems after installation?

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.

Is there a way to update RubyGems offline?

I am trying to install Ruby + WATIR to a Windows server which is in an isolated environment. Typically I would run the ruby installer followed by these two commands:
1) gem update --system
2) gem install watir
This is as per the instuctions here
The server I am now trying to install to does not have internet connectivity. This causes the commands above to fail.
Is there a way I can download the update packages required and copy them to the server to install locally?
When you do gem install it will search the current directory before looking to the remote source. You must specify the version if you are installing a local gem (see rubygems manual).
gem install copland-0.2.0.gem
I'm sorry, I don't know a way to update the gem system offline without doing a manual upgrade
I usually use
gem unpack blah-1.1.1.gem
to unpack the gem into individual Ruby files. Then you just need to make sure that directory is in your Ruby load path, and it's as good as a normal gem.

Resources