简体   繁体   English

安装 pg 时出错,需要 Ruby 版本 >= 2.2,即使 ruby >=2.2

[英]Error installing pg, requires Ruby version >= 2.2 even if ruby is >=2.2

$ ruby --version
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
$ which ruby
/usr/local/rvm/rubies/ruby-2.7.2/bin/ruby
$ which gem
/usr/local/rvm/rubies/ruby-2.7.2/bin/gem
$ sudo gem install pg
ERROR:  Error installing pg:
    pg requires Ruby version >= 2.2.

Error installing pg, requires Ruby version >= 2.2 even if ruby is >=2.2.安装 pg 时出错,需要 Ruby 版本 >= 2.2,即使 ruby >=2.2。

When using RVM, it is necessary for some environment variables to be loaded to RVM (and RVM-installed Rubies) to find its code.使用 RVM 时,需要将一些环境变量加载到 RVM(以及 RVM 安装的 Rubies)中才能找到它的代码。

When running your gem install command with sudo however, sudo will reset your $PATH and unset the required environment variables before executing the gem command with the sanitized $PATH .但是,当使用sudo运行gem install命令时, sudo 将重置您的$PATH并在使用经过清理的$PATH执行gem命令之前取消设置所需的环境变量。 With that, you will likely use your system ruby rather than your RVM-installed ruby.这样,您可能会使用您的系统 ruby 而不是 RVM 安装的 ruby。

In general, you should not use sudo to install Rubies or any gems when using RVM.一般来说,在使用 RVM 时,您不应该使用sudo来安装 Rubies 或任何 gem。 Instead, you generally can and should just use your normal user.相反,您通常可以而且应该只使用您的普通用户。

If you do have to use sudo with RVM for some reason, there is a special rvmsudo command which retains your RVM environment in the evaluated context.如果您出于某种原因必须将sudo与 RVM 一起使用,则有一个特殊的rvmsudo命令可以将您的 RVM 环境保留在评估的上下文中。 See https://rvm.io/integration/sudo for details.有关详细信息,请参阅https://rvm.io/integration/sudo However, as written above, you should try to avoid using this!但是,如上所述,您应该尽量避免使用它!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM