我如何使用Ubuntu的宝石? [英] How do I use gems with Ubuntu?

查看:124
本文介绍了我如何使用Ubuntu的宝石?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近升级到了Ubuntu 9.04,并且使用宝石时遇到问题。
我使用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:部分,可以看到宝石可以存储在我的笔记本电脑上的两个地方: /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 shell。您可以通过在shell提示符处键入以下内容来快速完成当前会话;让我们假装要将 /var/lib/gems/1.8/bin 添加到路径中:

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

然后按回车。将新目录附加到当前路径的末尾。注意 $ PATH /var/lib/gems/1.8/bin

$ b $之间的冒号b

要设置所有会话的值,您需要编辑 .profile .bashrc 文件并将相同的行添加到文件的末尾。我通常编辑我的 .bashrc 文件没有其他原因,除了这是我一直以来做的。完成后,保存文件,然后输入以下命令刷新环境:

在shell提示下。这将导致 .bashrc 被重读。



您可以随时通过输入>来检查 $ PATH 的当前值

  echo $ PATH 

at the shell提示符。



以下是我自己的一台服务器的示例,其中我的用户名是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宝石不会加载即使安装了使用多个不同版本的Ruby强调了一个常见问题;有时Gem环境和Gem路径不同步:

  rb(main):003:0> Gem.path 

=> [/opt/ruby1.9/lib/ruby1.9/gems/1.9.1]
irb(main):004:0>退出

这里的任何Ruby进程只在一个地方寻找它的Gems。

 :〜/ $ 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/

仔细看看gem环境的输出:

   - 创业板路径:
- /opt/ruby1.9/ lib / ruby​​ / gems / 1.9.1

这与Gem返回的路径不同。 path:

  [/ opt / ruby​​1.9 / lib / ruby​​1.9 / gems / 1.9.1] 

很难说究竟是什么导致 lib / ruby​​ 更改为 lib / ruby​​1.9 ,但很可能开发人员正在使用多个Ruby版本。快速 mv ln 将解决此问题。



如果您确实需要使用多个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 rails command does work.

I then installed capistrano and other gems, such as heroku. In order to do that, I used the command:

sudo gem install XXX

When I want to use the cap command it does not work:

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?

解决方案

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.

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:

bash

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

echo $PATH

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

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.

这篇关于我如何使用Ubuntu的宝石?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆