我如何使用Ubuntu的宝石? [英] How do I use gems with Ubuntu?
问题描述
我使用apt-get安装了Ruby,Rubygems和Rails。
rails
命令不起作用。然后我安装了capistrano和其他宝石,比如heroku。 为了做到这一点,我使用了命令:
sudo gem install XXX
当我想使用 cap
命令时,它不起作用:
bash:cap:找不到命令
这与其他gem命令是一样的。
我有一些特殊的事情可以让gem命令起作用吗?
我的宝石在哪里?
使用 gem environment
命令。例如:
chris @ chris-laptop:〜$ gem environment
RubyGems环境:
- RUBYGEMS VERSION:1.3.2
- RUBY VERSION:1.8.7(2008-08-11 patchlevel 72)[i486-linux]
- 安装目录:/ usr / lib / ruby / gems /1.8
- RUBY EXECUTABLE:/usr/bin/ruby1.8
- 可执行目录:/ usr / bin
- RUBYGEMS平台:
- ruby
- x86 -linux
- 创业板路径:
- /usr/lib/ruby/gems/1.8
- /home/chris/.gem/ruby/1.8
- 创业板配置:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- 远程来源:
如果您查看GEM PATHS:部分,可以看到宝石可以存储在我的笔记本电脑上的两个地方: 您还可以看到,可执行文件存储在EXECUTABLE DIRECTORY中,在这种情况下,它是 因为 如果由于某种原因,您的EXECUTABLE DIRECTORY不在您的路径上(例如, var / lib / gems / 1.8 / bin),那么你需要更新PATH变量。 假设你使用的是bash shell。您可以通过在shell提示符处键入以下内容来快速完成当前会话;让我们假装要将 然后按回车。将新目录附加到当前路径的末尾。注意 要设置所有会话的值,您需要编辑 在shell提示下。这将导致 您可以随时通过输入>来检查 at the shell提示符。 以下是我自己的一台服务器的示例,其中我的用户名是chris,计算机名称是chris-laptop: Ruby宝石不会加载即使安装了使用多个不同版本的Ruby强调了一个常见问题;有时Gem环境和Gem路径不同步: 这里的任何Ruby进程只在一个地方寻找它的Gems。 仔细看看gem环境的输出: 这与Gem返回的路径不同。 path: 很难说究竟是什么导致 如果您确实需要使用多个Ruby版本,那么您确实应该使用 rvm 。 I recently upgraded to Ubuntu 9.04 and I have issues using gems.
I installed Ruby, Rubygems and Rails using apt-get.
The I then installed capistrano and other gems, such as heroku.
In order to do that, I used the command: When I want to use the It is the same with the other gem commands. Do I have something particular to do so that the gem commands work? You can find where your gems are stored using the If you look at the "GEM PATHS:" section you can see that gems can be stored in two places on my laptop: You can also see that executables are stored in EXECUTABLE DIRECTORY which in this case is Because 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 and press return. That appends the new directory to the end of the current path. Note the colon between To set the value for all sessions you will need to edit either your at the shell prompt. That will cause the At any point you can check the current value of at the shell prompt. Here's a sample from one of my own servers, where my username is "chris" and the machine name is "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: Any Ruby process here is looking only in one place for its Gems. Look carefully at the output of gem environment: This isn't the same path as returned by Gem.path: It's hard to say what exactly caused If you do need to work with multiple Ruby versions then you really should be using rvm. 这篇关于我如何使用Ubuntu的宝石?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! /usr/lib/ruby/gems/1.8
或 .gem
/ usr / bin
。
/ usr / bin
运行 cap
, merb
, rails
等。
更新PATH
/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
文件没有其他原因,除了这是我一直以来做的。完成后,保存文件,然后输入以下命令刷新环境: .bashrc
被重读。
$ PATH
的当前值
echo $ PATH
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:〜$
我的宝石不会加载!
rb(main):003:0> Gem.path
=> [/opt/ruby1.9/lib/ruby1.9/gems/1.9.1]
irb(main):004:0>退出
:〜/ $ gem env
RubyGems环境:
- RUBYGEMS版本:1.3.7
- RUBY VERSION:1.9.1(2009-05-12 patchlevel 129)[x86_64-linux]
- 安装目录:/opt/ruby1.9/lib/ruby/gems/1.9.1
- RUBY EXECUTABLE:/opt/ruby1.9/bin/ruby1.9
- 可执行目录:/opt/ruby1.9/bin
- RUBYGEMS平台:
- ruby
- x86_64-linux
- 创业板路径:
- /opt/ruby1.9/lib/ruby/gems/1.9.1
- /home/mark/.gem/ruby/1.9 .1
- 创业板配置:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- 远程来源:
- http://rubygems.org/
- 创业板路径:
- /opt/ruby1.9/ lib / ruby / gems / 1.9.1
[/ opt / ruby1.9 / lib / ruby1.9 / gems / 1.9.1]
lib / ruby
更改为 lib / ruby1.9
,但很可能开发人员正在使用多个Ruby版本。快速 mv
或 ln
将解决此问题。
rails
command does work.sudo gem install XXX
cap
command it does not work:bash: cap: command not found
Where are my Gems?
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:
/usr/lib/ruby/gems/1.8
or in the .gem
directory in my home dir./usr/bin
./usr/bin
is in my path this lets me run cap
, merb
, rails
etc.Updating your PATH
/var/lib/gems/1.8/bin
to the path:export PATH=$PATH:/var/lib/gems/1.8/bin
$PATH
and /var/lib/gems/1.8/bin
.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:bash
.bashrc
to get reread. $PATH
by typingecho $PATH
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!
rb(main):003:0> Gem.path
=> ["/opt/ruby1.9/lib/ruby1.9/gems/1.9.1"]
irb(main):004:0> exit
:~/$ 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/
- GEM PATHS:
- /opt/ruby1.9/lib/ruby/gems/1.9.1
["/opt/ruby1.9/lib/ruby1.9/gems/1.9.1"]
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.