'sudo gem install' 或 'gem install' 和 gem 位置 [英] 'sudo gem install' or 'gem install' and gem locations

查看:42
本文介绍了'sudo gem install' 或 'gem install' 和 gem 位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行 'sudo gem list --local' 和 'gem list --local' 给我不同的结果.我的 gem 路径设置为我的主文件夹,并且只包含来自gem list --local"的 gem.

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

在我的计算机上的不同目录中安装 gem 可能不太好,所以我应该将 gem 路径设置为不同,并且在安装某些东西时我应该总是使用 sudo 吗?

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"

~/.bash_profile 为空.

~/.bash_profile is empty.

推荐答案

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

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

相反,我建议您安装 RVM 并开始使用便携式宝石屋和不同版本的 Ruby 都住在一个屋檐下.

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​​ 环境和一组 gem.

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

使用 sudo 安装 gems 比 gem install 更糟糕的原因是因为它为 ALL USERS 安装 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.

如果您决定要吹掉所有宝石并重新开始,以非 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.

如果你决定使用 RVM 那么使用 sudo 会引起各种奇怪的事情,因为你通过 RVM 安装的每个 Ruby 版本都有自己的 GEM_HOME.

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.

此外,如果您能让您的开发环境尽可能接近您的生产环境,那就太好了,并且在生产环境中,您很可能会以非 root 用户身份安装 gem.

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.

这篇关于'sudo gem install' 或 'gem install' 和 gem 位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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