“sudo gem安装”或“gem安装”和“gem安装”

时间:2022-07-07 10:46:40

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

运行“sudo gem列表—local”和“gem列表—local”会给我不同的结果。我的gem路径被设置到我的home文件夹中,并且只包含来自“gem列表——local”的gem。

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?

在我的计算机上的不同目录中安装gem可能不太好,所以我是否应该设置不同的gem路径,以及在安装某些东西时是否应该始终使用sudo ?

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

~/.bash_profile is empty.

~ /。bash_profile是空的。

7 个解决方案

#1


130  

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

与所有其他帖子相反,我建议在安装gems时不要使用sudo。

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,并开始一个快乐的生活与便携式宝石家园和不同版本的Ruby都生活在一个屋檐下。

For the uninitiated, from the documentation:

对于未发起的,从文件:

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

RVM是一个命令行工具,允许我们轻松地安装、管理和使用多个ruby环境和一组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.

使用sudo安装gems比仅仅安装gem更糟糕的原因是,它将所有用户的gem作为root用户安装。如果你是唯一使用这台机器的人,这可能没问题,但如果你不是,这可能会引起奇怪。

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.

如果您决定要使用RVM,那么使用sudo将导致各种奇怪的结果,因为通过RVM安装的每个Ruby版本都有自己的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.

另外,如果您能够尽可能地将开发环境与生产环境尽可能地接近,那么在生产中您很可能会将gem作为非根用户安装。

#2


102  

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

您还可以在本地环境中(不使用sudo)安装gems

gem install --user-install <gemname>

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

你可以通过查看宝石环境下的天马行空来检查宝石的去向。在我的例子中是“~/.gem/ruby/1.8”。

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

如果您需要一些本地安装的二进制文件添加到您的路径,您可以添加一些东西到您的bashrc中:

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

(from http://guides.rubygems.org/faqs/#user-install)

(来自http://guides.rubygems.org/faqs/ user-install)

#3


27  

Better yet, put --user-install in your ~/.gemrc file so you don't have to type it every time

更好的是,把用户安装在你的~/。gemrc文件,所以你不必每次都输入它

gem: --user-install

#4


7  

Related (for bundler users), if you want a lighter alternative to RVM which will put everything in a user-specific well known directory, I recommend using:

相关(对于bundler用户),如果您想要一个更轻的RVM替代品,将所有内容都放在特定于用户的知名目录中,我建议使用:

bundle install --path $HOME/.gem

if you want to install gems to the same place that

如果你想在同一个地方安装宝石

gem install --user-install GEMNAME

will install them, .gem/ruby/RUBYVERSION in your homedir. (See the other comment on this question about --user-install.)

将在您的homedir中安装它们。gem/ruby/RUBYVERSION。(请参阅关于用户安装的其他评论。)

This will make the gems visible to gem list, uninstallable via gem uninstall, etc. without needing sudo access. Runnable scripts installed by gem or bundler can be put into your path by adding

这将使宝石列表可见,无需sudo访问就可以通过宝石卸载等方式卸载。可以通过添加将gem或bundler安装的可运行脚本放入路径中

$HOME/.gem/ruby/RUBYVERSION/bin

to your $PATH. gem itself tells you about this if it isn't set when you do gem install --user-install.

您的$ PATH。gem自己告诉您,如果在执行gem安装时没有设置的话——用户安装。

#5


7  

In case you

如果你

  • installed ruby gems with sudo
  • 用sudo安装红宝石宝石。
  • want to install gems without sudo
  • 想要安装宝石没有sudo
  • don't want to install rvm/rbenv
  • 不要安装rvm/rbenv。

add the following to your .bash_profile :

向.bash_profile添加以下内容:

export GEM_HOME=/Users/‹your_user›/.gem
export PATH="$GEM_HOME/bin:$PATH"

Open a new tab in Terminal OR source ~/.bash_profile and you're good to go!

在终端或源代码中打开一个新的选项卡~/。bash_profile你可以走了!

#6


5  

sudo gem install --no-user-install <gem-name>

will install your gem globally, i.e. it will be available to all user's contexts.

将在全球安装您的gem,即所有用户的上下文都可以使用它。

#7


2  

You can install gems into a specific folder (example vendor/) in your Rails app using :

您可以使用以下方法将gems安装到Rails应用程序的特定文件夹(例如vendor/)中:

bundle install --path vendor

#1


130  

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

与所有其他帖子相反,我建议在安装gems时不要使用sudo。

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,并开始一个快乐的生活与便携式宝石家园和不同版本的Ruby都生活在一个屋檐下。

For the uninitiated, from the documentation:

对于未发起的,从文件:

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

RVM是一个命令行工具,允许我们轻松地安装、管理和使用多个ruby环境和一组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.

使用sudo安装gems比仅仅安装gem更糟糕的原因是,它将所有用户的gem作为root用户安装。如果你是唯一使用这台机器的人,这可能没问题,但如果你不是,这可能会引起奇怪。

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.

如果您决定要使用RVM,那么使用sudo将导致各种奇怪的结果,因为通过RVM安装的每个Ruby版本都有自己的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.

另外,如果您能够尽可能地将开发环境与生产环境尽可能地接近,那么在生产中您很可能会将gem作为非根用户安装。

#2


102  

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

您还可以在本地环境中(不使用sudo)安装gems

gem install --user-install <gemname>

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

你可以通过查看宝石环境下的天马行空来检查宝石的去向。在我的例子中是“~/.gem/ruby/1.8”。

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

如果您需要一些本地安装的二进制文件添加到您的路径,您可以添加一些东西到您的bashrc中:

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

(from http://guides.rubygems.org/faqs/#user-install)

(来自http://guides.rubygems.org/faqs/ user-install)

#3


27  

Better yet, put --user-install in your ~/.gemrc file so you don't have to type it every time

更好的是,把用户安装在你的~/。gemrc文件,所以你不必每次都输入它

gem: --user-install

#4


7  

Related (for bundler users), if you want a lighter alternative to RVM which will put everything in a user-specific well known directory, I recommend using:

相关(对于bundler用户),如果您想要一个更轻的RVM替代品,将所有内容都放在特定于用户的知名目录中,我建议使用:

bundle install --path $HOME/.gem

if you want to install gems to the same place that

如果你想在同一个地方安装宝石

gem install --user-install GEMNAME

will install them, .gem/ruby/RUBYVERSION in your homedir. (See the other comment on this question about --user-install.)

将在您的homedir中安装它们。gem/ruby/RUBYVERSION。(请参阅关于用户安装的其他评论。)

This will make the gems visible to gem list, uninstallable via gem uninstall, etc. without needing sudo access. Runnable scripts installed by gem or bundler can be put into your path by adding

这将使宝石列表可见,无需sudo访问就可以通过宝石卸载等方式卸载。可以通过添加将gem或bundler安装的可运行脚本放入路径中

$HOME/.gem/ruby/RUBYVERSION/bin

to your $PATH. gem itself tells you about this if it isn't set when you do gem install --user-install.

您的$ PATH。gem自己告诉您,如果在执行gem安装时没有设置的话——用户安装。

#5


7  

In case you

如果你

  • installed ruby gems with sudo
  • 用sudo安装红宝石宝石。
  • want to install gems without sudo
  • 想要安装宝石没有sudo
  • don't want to install rvm/rbenv
  • 不要安装rvm/rbenv。

add the following to your .bash_profile :

向.bash_profile添加以下内容:

export GEM_HOME=/Users/‹your_user›/.gem
export PATH="$GEM_HOME/bin:$PATH"

Open a new tab in Terminal OR source ~/.bash_profile and you're good to go!

在终端或源代码中打开一个新的选项卡~/。bash_profile你可以走了!

#6


5  

sudo gem install --no-user-install <gem-name>

will install your gem globally, i.e. it will be available to all user's contexts.

将在全球安装您的gem,即所有用户的上下文都可以使用它。

#7


2  

You can install gems into a specific folder (example vendor/) in your Rails app using :

您可以使用以下方法将gems安装到Rails应用程序的特定文件夹(例如vendor/)中:

bundle install --path vendor