Rails:您的用户帐户不允许安装到系统 RubyGems
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42843948/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Rails: Your user account isn't allowed to install to the system RubyGems
提问by William Entriken
I am running the command
我正在运行命令
bundle install
in a project folder. In some project folders it will produce an error and in other projects folders it will not produce an error. The error is:
在项目文件夹中。在某些项目文件夹中,它会产生错误,而在其他项目文件夹中,它不会产生错误。错误是:
Your user account isn't allowed to install to the system RubyGems
您的用户帐户不允许安装到系统 RubyGems
I know this can be fixed by following the recommended advice:
我知道这可以通过遵循推荐的建议来解决:
bundle install --path vendor/bundle
bundle install --path vendor/bundle
My question is why is the behavior inconsistent?
我的问题是为什么行为不一致?
回答by Antonio Vinicius Menezes Medei
In my case, I solved doing just what the error message suggests:
就我而言,我解决了按照错误消息所建议的操作:
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/
So, instead of:
所以,而不是:
bundle install
I ran:
我跑了:
bundle install --path vendor/bundle
That was the solution for this guy.
这就是这个家伙的解决方案。
The downside of that solution is that it creates a vendorfolder inside the current folder, which can be added to .gitignoreif it is to distribute the application through Git.
该解决方案的缺点是它vendor在当前文件夹中创建了一个文件夹,.gitignore如果要通过 Git 分发应用程序,可以将其添加到该文件夹中。
回答by isaacsloan
Usually if you're using RVM, rbenv or chruby to install Ruby, all the gems will be installed in your home folder under ~/.rbenv/ruby-version/...
通常如果你使用 RVM、rbenv 或 chruby 来安装 Ruby,所有的 gems 都会安装在你的主文件夹下 ~/.rbenv/ruby-version/...
If you're using your system Ruby though (the one that is installed by default) the gems are installed alongside it in a location that you don't have access to without sudo.
如果你使用你的系统 Ruby(默认安装的那个),gems 会安装在它旁边的一个位置,如果没有sudo.
My guess would be that your version manager defaults to the system Ruby but some of your projects have a .ruby-version file in them that tells it to use a different version of Ruby which you have access to.
我的猜测是您的版本管理器默认使用系统 Ruby,但您的某些项目中有一个 .ruby-version 文件,告诉它使用您有权访问的不同版本的 Ruby。
回答by Michael Durrant
Good rbenv fix
好的 rbenv 修复
- Avoids sudo
- Avoids install to vendor/bundle
- 避免使用 sudo
- 避免安装到供应商/捆绑包
The problem, at least for me, was that bundler itself wasn't installed in my rbenv ruby version. Even though bundler existed and seemed usable... except the permissions error.
至少对我而言,问题在于我的 rbenv ruby 版本中没有安装捆绑程序本身。 即使 bundler 存在并且似乎可用......除了权限错误。
One of the things that clued me in was that at the actual command line itself I could install gems ok and not get the error message. I did this for a while as a work-around until I decided to fix the problem permanently as shown below:
给我提供线索的一件事是,在实际的命令行本身,我可以正常安装 gems 而不会收到错误消息。我这样做了一段时间作为解决方法,直到我决定永久解决问题,如下所示:
To fix it I did:
为了解决它,我做了:
rbenv local 2.5.0 # Make sure I'm using a local version that exists
gem list | grep bundler # Note no output! Need to fix that!
gem install bundler
rbenv rehash
bundle (within my project that has a Gem file)
回答by Promise Preston
I had a similar experience. I would have simply ran the code below to fix it temporarily
我有过类似的经历。我会简单地运行下面的代码来临时修复它
bundle install --path vendor/bundle
The downside to this is that it does not solve the issue permanently, as the issue will re-surface when you start out with another Ruby on Rails Applications.
这样做的缺点是它不能永久解决问题,因为当您开始使用另一个 Ruby on Rails 应用程序时,问题会再次出现。
I tried this solution, but it did not work for me:
我试过这个解决方案,但它对我不起作用:
Display a list of all your local gems for the bundler gem
显示 bundler gem 的所有本地 gem 列表
gem list bundler
N/B:The command above is for rbenv version manager, the one for rvm might be different
N/B:上面的命令是针对 rbenv 版本管理器的,针对 rvm 的可能会有所不同
This will display the versions of the bundler gem installed locally
这将显示本地安装的 bundler gem 的版本
bundler (2.0.2, default: 1.17.3, 1.10.6)
And then ran the code below below to uninstall version 1.10.6
然后运行下面的代码来卸载版本 1.10.6
gem uninstall bundler
Afterwhich I ran the code below to rehash rbenv
之后我运行下面的代码来重新哈希rbenv
rbenv rehash
However, this did not solve the issue.
然而,这并没有解决问题。
Here's how I solved it;
这是我解决它的方法;
The issue was that I mistakenly ran a bundle installoperation with administrative rights, that is:
问题是我错误地运行了bundle install具有管理权限的操作,即:
sudo bundle install
To solve the issue I ran the code below to change the ownership of the files and directories.
为了解决这个问题,我运行了下面的代码来更改文件和目录的所有权。
For rbenvusers:
对于rbenv用户:
sudo chown -R $USER ~/.rbenv
And for RVMusers
对于RVM用户
sudo chown -R $USER ~/.rvm
That's it.
就是这样。
I hope this helps
我希望这有帮助
回答by ToTenMilan
Using RVM:
使用 RVM:
You have to install rvmfor your single user (standard user / non root user), in your $HOMEdirectory (It's not installed if you don't have /home/youruser/.rvmdirectory.
您必须在您的目录中rvm为您的单个用户(标准用户/非 root 用户)$HOME安装(如果您没有/home/youruser/.rvm目录,则不会安装。
As is specified on rvm siteunder "Single-User Install Location: ~/.rvm/" section, to install rvmfor single user run:
正如rvm 站点上“单用户安装位置:~/.rvm/”部分下的指定,要rvm为单用户运行安装:
cd
\curl -sSL https://get.rvm.io | bash -s -- --ignore-dotfiles
Now, rvmshould be installed. As in further prompt, refresh rvm(with your username provided):
现在,rvm应该安装了。在进一步提示中,刷新rvm(提供您的用户名):
source /home/---YOURUSERNAME---/.rvm/scripts/rvm
To prevent prompts for installing sudo-need packages, run:
要防止提示安装 sudo-need 软件包,请运行:
rvm autolibs disable
You can install Ruby for your user only, in version 2.5 (or any other, listed in rvm list known)
您只能为您的用户安装 Ruby 版本 2.5(或任何其他版本,列于rvm list known)
rvm install 2.5
Explanation:
解释:
You probably try to install rvm using sudoand maybe with this package for ubuntubut you don't have sudo permissions.
您可能尝试使用 rvm 安装 rvmsudo并且可能使用此包为 ubuntu 安装,但您没有 sudo 权限。
This prompt is telling you that you can't bundle gems globally for the whole system, which may be good for your private home machine but not for your corporate user(machine), which is often administered by someone else.
这个提示告诉你,你不能为整个系统全局捆绑 gems,这可能对你的私人家用机器有好处,但对你的公司用户(机器)不利,这通常由其他人管理。
If rvm will be installed in your $HOMEgems will be bundled there, like usual.
如果 rvm 将安装在您的$HOMEgems 中,它将像往常一样捆绑在那里。
Behavior may be inconsistent because other users have rvminstalled in their $HOMEdirectory
行为可能不一致,因为其他用户已经rvm安装在他们的$HOME目录中
回答by Oleg Sobchuk
Recently faced the same issue. I use rvm
最近遇到了同样的问题。我用rvm
sudo chown -R $USER ~/.rvmhelped for me
sudo chown -R $USER ~/.rvm对我有帮助
回答by pocheptsov
In my case, I had an existing $BUNDLE_PATHwithout enough permissions to the bundler user to write in.
就我而言,我有一个现有$BUNDLE_PATH的捆绑用户没有足够的权限来写入。
Your user account isn't allowed to install to the system RubyGems
bundle install --path vendor/bundle
回答by Bhudeb Kr Sarkar
- Open your bashrcor zshrcfile.
- Add
eval "$(rbenv init -)"at the end of the file and save it. - Run source ~/.zshrc or source ~/.bashrc
- 打开您的bashrc或zshrc文件。
eval "$(rbenv init -)"在文件末尾添加并保存。- 运行 source ~/.zshrc 或 source ~/.bashrc
You can also close and open the terminal. bundle install and you are good to go.
您还可以关闭和打开终端。捆绑安装,您就可以开始了。
回答by malinois
Delete
删除
sudo mv ~/.bundle /tmp
Try reinstall
尝试重新安装
bundle install

