Program Tip

Ubuntu에서 gem을 어떻게 사용합니까?

programtip 2020. 10. 16. 07:57
반응형

Ubuntu에서 gem을 어떻게 사용합니까?


최근 Ubuntu 9.04로 업그레이드했는데 gem을 사용하는 데 문제가 있습니다. apt-get을 사용하여 Ruby, Rubygems 및 Rails를 설치했습니다. rails명령은 작업을 수행합니다.

그런 다음 카피 스트라 노와 heroku와 같은 다른 보석을 설치했습니다. 이를 위해 다음 명령을 사용했습니다.

sudo gem install XXX

cap명령 을 사용하고 싶을 때 작동하지 않습니다.

bash: cap: command not found

다른 gem 명령과 동일합니다.

gem 명령이 작동하도록 특별히해야 할 일이 있습니까?


내 보석은 어디에 있습니까?

gem environment명령을 사용하여 보석이 저장된 위치를 찾을 수 있습니다 . 예를 들면 :

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:

"GEM PATHS :"섹션을 보면 gem이 랩톱의 두 위치에 저장 될 수 있음을 알 수 있습니다. /usr/lib/ruby/gems/1.8또는 .gem내 홈 디렉토리 디렉토리에 있습니다.

또한 실행 파일이 EXECUTABLE DIRECTORY (이 경우 /usr/bin.

때문에 /usr/bin내 경로에이 나를 실행할 수 있습니다 cap, merb, rails

PATH 업데이트

어떤 이유로 EXECUTABLE DIRECTORY가 경로에없는 경우 (예 : /var/lib/gems/1.8/bin 인 경우) PATH 변수를 업데이트해야합니다.

bash 쉘을 사용하고 있다고 가정합니다. 쉘 프롬프트에서 다음을 입력하여 현재 세션에 대해이 작업을 빠르게 수행 할 수 있습니다. /var/lib/gems/1.8/bin경로 에 추가하고 싶다고 가정 해 보겠습니다 .

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

리턴을 누르십시오. 그러면 현재 경로의 끝에 새 디렉터리가 추가됩니다. $PATH사이의 콜론에 유의하십시오./var/lib/gems/1.8/bin

모든 세션에 대한 값을 설정하려면 사용자 .profile또는 .bashrc파일 을 편집 하고 파일 끝에 동일한 행을 추가해야합니다. 저는 보통 .bashrc제가 항상 해왔 던 것 외에 다른 이유없이 파일을 편집 합니다. 완료되면 파일을 저장하고 다음을 입력하여 환경을 새로 고칩니다.

bash

쉘 프롬프트에서. 그러면이 .bashrc다시 읽게됩니다.

언제든지 $PATH입력하여 의 현재 값을 확인할 수 있습니다.

echo $PATH

쉘 프롬프트에서.

다음은 내 사용자 이름이 "chris"이고 컴퓨터 이름이 "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:~$ 

내 보석이로드되지 않습니다!

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


As noted by @Chris you need to add the gems environment to your path. You can do this by:

echo 'export PATH=$PATH:/var/lib/gems/1.8/bin' | tee --append ~/.bashrc

The folder in which gems are stored must be on your PATH, for example mine is:

/home/victor/.gem/ruby/1.8/bin

Check your path by typing

echo $PATH

It seens that when installing rubygems, now in ubuntu 9.04, I have this problem. I noticed that in "gem environment" the executable directory is "/var/lib/gems/1.8/bin", instead of "/usr/bin"... This is a problem with rubygems or with ubuntu 9.04??

The solution that I encountered is to add "/var/lib/gems/1.8/bin" to my $PATH doing this: export PATH=$PATH:/var/lib/gems/1.8/bin But it don't is saved... how can I save my path?

Thanks...

Resolvi: coloquei o export PATH=$PATH:/var/lib/gems/1.8/bin no ~/.bashrc! =]


mkmf is part of the ruby1.9.1-dev package. This package contains the header files needed for extension libraries for Ruby 1.9.1. You need to install the ruby1.9.1-dev package by doing:

sudo apt-get install ruby1.9.1-dev

참고URL : https://stackoverflow.com/questions/909673/how-do-i-use-gems-with-ubuntu

반응형