Rvm 进行gem安装时必须输入密码Your user account isn't allowed to install to the system RubyGems 解决方案

时间:2023-03-09 17:48:54
Rvm 进行gem安装时必须输入密码Your user account isn't allowed to install to the system RubyGems 解决方案

今天开发过程中,从master拉下代码后重启项目,想用控制台时,却发现需要密码??并且三次密码确认后还是疯狂报错。

当时第一想到是rvm版本不一致,随即则检查了版本跟gem生成,当确认rvm版本无误时,且强制使用sudo安装却需要一条条执行gem install ***安装gem包时,就令我抓狂了。

警告提示如下:

Your user account isn't allowed to install to the system RubyGems.
You can cancel this installation and run: bundle install --path vendor/bundle to install the gems into ./vendor/bundle/, or you can enter your password
and install the bundled gems to RubyGems using sudo.

或者如下:

RVM is not a function, selecting rubies with 'rvm use ...' will not work.

You need to change your terminal emulator preferences to allow login shell.
Sometimes it is required to use `/bin/bash --login` as the command.
Please visit https://rvm.io/integration/gnome-terminal/ for an example.

猜测原因:

rbenv 要往你系统的自带Ruby里面安装gem,但是你的用户帐户不允许系统安装RubyGems,所以要你输入密码赋予权限

解决方案(控制台依次输入):

 echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"' >>~/.bashrc

 source ~/.bashrc

 ruby -v

然后就解决了,可以继续嗨皮开发了!!