Linux ruby gem path

How to install a downloaded Ruby gem file?

Maybe I have not fully understood the question. But if you just want to install a gem that you have on your local machine, all you need to do from the console is go into the directory containing your gem and gem install —local your.gem .

Just some more clarification in case you need to build / install your own gem file in this example foo-bar.

gem build foo-bar.gemspec gem install --local foo-bar-0.1.0.gem 

I was researching how to do this and this post was first result 🙂

@valk well it depends on version specified in *.gemspec . Worth of mentioning is that you do not need —local handle but documentation says it does so I’ve respected it.

@HarisKrajina It is helpful to have —local because it stops it from checking each source for the repo and save a bit of time. Particularly useful if you have edited a gem found online (Did this to make it compatible with another program).

The problem is that gem install is looking for gems to install in its default directory. You can find out where that is by running:

This will give you something like:

> RubyGems Environment: > - RUBYGEMS VERSION: 1.3.6 > - RUBY VERSION: 1.8.6 (2007-09-24 patchlevel 111) [i486-linux] > - INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.8 > - RUBY EXECUTABLE: /usr/bin/ruby1.8 > - EXECUTABLE DIRECTORY: /usr/bin > - RUBYGEMS PLATFORMS: > - ruby > - x86-linux > - GEM PATHS: > - /usr/lib/ruby/gems/1.8 > - /home/adminuser/.gem/ruby/1.8 

The GEM PATHS locations is where gem install is expecting to find gems to install. So, the solution to your problem would be to copy the gem from its current location to the expected directory, i.e.

$ cp my.gem /home/adminuser/.gem/ruby/1.8/ 

If you then run gem install it will pick up your gem and install it. Make sure you run the copy command as superuser (sudo, if you’re running Ubuntu like me)

P.S If, when you run $ gem environment, you get an «undefined method ‘manage_gems’ for Gem:Module (NoMethodError)» error, then edit /usr/bin/gem and ensure that the first three lines of the file look like this:

Источник

How to set Ruby GEM_HOME and GEM_PATH

I’m a NOVICE user of Linux and using Linux mint 17.1 I’ve reinstalled Linux Mint 20 time in last 3 days for that issue but could not fix it I’m trying to install ruby on rails using rvm what happened is if start a new Linux installation and try installing gems and ruby and stuff in one terminal session it installed successfully as soon as I close the terminal session I can’t get those gems. By reinstalling it over 20 times in last 3 days I’ve searched on the web too. I’ve been told to put environment variable in /etc/environment I echoed path in that session and pasted that in /etc/environment file. even now I don’t get my installed gems when I typed rvm -v I get the following errors

Warning: PATH set to RVM ruby but GEM_HOME and/or GEM_PATH not set, see: https://github.com/wayneeseguin/rvm/issues/3212 Warning! PATH is not properly set up, $GEM_HOME is not set, usually this is caused by shell initialization files - check them for 'PATH=. ' entries, it might also help to re-add RVM to your dotfiles: 'rvm get stable --auto-dotfiles', to fix temporarily in this shell session run: 'rvm use ruby-2.2.2'. rvm 1.26.11 (latest) by Wayne E. Seguin , Michal Papis [https://rvm.io/] 
echo $PATH /home/sharif/.rvm/gems/ruby-2.2.2/bin:/home/sharif/.rvm/gems/ruby-2.2.2@global/bin:/home/sharif/.rvm/rubies/ruby-2.2.2/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/sharif/.rvm/bin 

Источник

Читайте также:  Linux пишет no such file or directory

‘sudo gem install’ or ‘gem install’ and gem locations

Running ‘ sudo gem list —local ‘ and ‘ gem list —local ‘ give me differing results. My gem path is set to my home folder and only contains the gems from ‘ gem list —local ‘. It’s probably not good to have gems installed in different directories on my computer, so should I have the gem path set differently, and should I always use sudo when installing something?

my ~/.profile export PATH=/opt/local/bin:/opt/local/sbin:$PATH export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH" 

I think this is a valid question for those of us who have to use a gem that requires root privileges.

Related: stackoverflow.com/questions/21141584/…. I use rbenv for managing Ruby versions and ran into an issue because I used sudo gem install rails instead of gem install rails .

«I think this is a valid question for those of us who have to use a gem that requires root privileges.» I think any gem that needs root privileges, either to be installed, or to run, is highly suspicious. Gems should be able to run in a sandbox and run with the user’s permissions.

sudo is a loaded gun pointed toward your foot. Using it without understanding what it does and how it can affect your system is like pulling the trigger with your eyes closed. You might shoot a hole in your foot, you might not, but either way you don’t want to run the risk unless you know how to undo the damage. Using sudo writes into the system-owned Ruby, which, on Mac OS, was installed by Apple for their own uses. We can piggyback on it, but changing the wrong thing can break their code. That’s why we install from source or use something else to install where we can safely tweak it.

8 Answers 8

You can install gems in your local environment (without sudo ) with

I recommend that so you don’t mess with your system-level configuration even if it’s a single-user computer.

You can check where the gems go by looking at gempaths with gem environment . In my case it’s «~/.gem/ruby/1.8».

Читайте также:  Linux посмотреть установленные пакеты rpm

If you need some binaries from local installs added to your path, you can add something to your bashrc like:

if which ruby >/dev/null && which gem >/dev/null; then PATH="$(ruby -r rubygems -e 'puts Gem.user_dir')/bin:$PATH" fi 

I am creating a gem and according to manuals I have to do rake install and to fix the sudo isse, I had to patch manually the /Library/Ruby/Gems/2.0.0/gems/bundler-1.7.3/lib/bundler/gem_helper.rb adding —user-install there. Can’t find better solution, because looks like rake install doesn’t accept additional parameters.

I am absolutely thrilled with that first command. I have been trying to install gems and have been having issues because I don’t have sudo privileges. That command worked.

ruby -r rubygems -e ‘puts Gem.dir’ and ruby -r rubygems -e ‘puts Gem.user_dir’ print paths of global and user gems. gem env home and gem env user_gemhome (Ruby 3.2.0) do the same things.

Contrary to all the other posts I suggest NOT using sudo when installing gems.

Instead I recommend you install RVM and start a happy life with portable gem homes and different version of Ruby all living under one roof.

RVM is a command line tool which allows us to easily install, manage and work with multiple ruby environments and sets of gems.

The reason why installing gems with sudo is worse than just gem install is because it installs the gems for ALL USERS as root . This might be fine if you’re the only person using the machine, but if you’re not it can cause weirdness.

If you decide you want to blow away all your gems and start again it’s much easier, and safer, to do so as a non-root user.

If you decide you want to use RVM then using sudo will cause all kinds of weirdness because each Ruby version you install through RVM has its own GEM_HOME.

Also, it’s nice if you can make your development environment as close to your production environment as possible, and in production you’ll most likely install gems as a non-root user.

Источник

How do I use gems with Ubuntu?

I recently upgraded to Ubuntu 9.04 and I have issues using gems. I installed Ruby, Rubygems and Rails using apt-get. The rails command does work. I then installed capistrano and other gems, such as heroku. In order to do that, I used the command:

bash: cap: command not found 

It is the same with the other gem commands. Do I have something particular to do so that the gem commands work?

5 Answers 5

Where are my Gems?

You can find where your gems are stored using the gem environment command. For example:

chris@chris-laptop:~$ gem environment RubyGems Environment: - RUBYGEMS VERSION: 1.3.2 - RUBY VERSION: 1.8.7 (2008-08-11 patchlevel 72) [i486-linux] - INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.8 - RUBY EXECUTABLE: /usr/bin/ruby1.8 - EXECUTABLE DIRECTORY: /usr/bin - RUBYGEMS PLATFORMS: - ruby - x86-linux - GEM PATHS: - /usr/lib/ruby/gems/1.8 - /home/chris/.gem/ruby/1.8 - GEM CONFIGURATION: - :update_sources => true - :verbose => true - :benchmark => false - :backtrace => false - :bulk_threshold => 1000 - REMOTE SOURCES: 

If you look at the «GEM PATHS:» section you can see that gems can be stored in two places on my laptop: /usr/lib/ruby/gems/1.8 or in the .gem directory in my home dir.

Читайте также:  Запустить диспетчер задач linux mint

You can also see that executables are stored in EXECUTABLE DIRECTORY which in this case is /usr/bin .

Because /usr/bin is in my path this lets me run cap , merb , rails etc.

Updating your PATH

If for some reason your EXECUTABLE DIRECTORY isn’t on your path (for example if it is /var/lib/gems/1.8/bin) then you need to update your PATH variable.

Assuming that you are using the bash shell. You can do this quickly for the current session by typing the following at the shell prompt; let’s pretend that you want to add /var/lib/gems/1.8/bin to the path:

export PATH=$PATH:/var/lib/gems/1.8/bin 

and press return. That appends the new directory to the end of the current path. Note the colon between $PATH and /var/lib/gems/1.8/bin

To set the value for all sessions you will need to edit either your .profile or .bashrc file and add the same line to the end of the file. I usually edit my .bashrc file for no reason other than that’s what I’ve always done. When finished, save the file and then refresh your environment by typing:

at the shell prompt. That will cause the .bashrc to get reread.

At any point you can check the current value of $PATH by typing

Here’s a sample from one of my own servers, where my username is «chris» and the machine name is «chris-laptop»:

chris@chris-laptop:~$ chris@chris-laptop:~$ echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games chris@chris-laptop:~$ chris@chris-laptop:~$ export PATH=$PATH:/var/lib/gems/1.8/bin chris@chris-laptop:~$ chris@chris-laptop:~$ echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/var/lib/gems/1.8/bin chris@chris-laptop:~$ 

My Gem won’t load!

«Ruby gems won’t load even though installed» highlights a common problem using multiple different versions of Ruby; Sometimes the Gem environment and Gem path get out of sync:

rb(main):003:0> Gem.path => ["/opt/ruby1.9/lib/ruby1.9/gems/1.9.1"] irb(main):004:0> exit 

Any Ruby process here is looking only in one place for its Gems.

:~/$ gem env RubyGems Environment: - RUBYGEMS VERSION: 1.3.7 - RUBY VERSION: 1.9.1 (2009-05-12 patchlevel 129) [x86_64-linux] - INSTALLATION DIRECTORY: /opt/ruby1.9/lib/ruby/gems/1.9.1 - RUBY EXECUTABLE: /opt/ruby1.9/bin/ruby1.9 - EXECUTABLE DIRECTORY: /opt/ruby1.9/bin - RUBYGEMS PLATFORMS: - ruby - x86_64-linux - GEM PATHS: - /opt/ruby1.9/lib/ruby/gems/1.9.1 - /home/mark/.gem/ruby/1.9.1 - GEM CONFIGURATION: - :update_sources => true - :verbose => true - :benchmark => false - :backtrace => false - :bulk_threshold => 1000 - REMOTE SOURCES: - http://rubygems.org/ 

Look carefully at the output of gem environment:

 - GEM PATHS: - /opt/ruby1.9/lib/ruby/gems/1.9.1 

This isn’t the same path as returned by Gem.path:

["/opt/ruby1.9/lib/ruby1.9/gems/1.9.1"] 

It’s hard to say what exactly caused lib/ruby to change to lib/ruby1.9 but most likely the developer was working with multiple Ruby versions. A quick mv or ln will solve the problem.

If you do need to work with multiple Ruby versions then you really should be using rvm.

Источник

Оцените статью
Adblock
detector