在本地项目目录中安装 gem 时,如何确定正确的 gem 文件路径应该是什么?

问题描述

我使用的是 Ruby 2.6 和 Rail 5。我想安装以下 gem

$ gem install ffi -v '1.9.18' -- --with-cflags="-Wno-error=implicit-function-declaration"
Fetching ffi-1.9.18.gem
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.

但以上尝试将其安装在全局位置,我更愿意将其安装在我使用配置的项目目录中

bundle config set --local path 'vendor/bundle'

根据文档,我可以将其添加到我的“gem install”命令中

--local path_to_gem/filename.gem

但我的问题是“path_to_gem/filename.gem”需要是什么才能正确安装这个 ffi gem,或者我可以做些什么?

解决方法

考虑使用 RVM 并利用其 gemset 功能。 Rails 项目与 Node 项目不同,Node 项目在 node_modules 目录中存放所有依赖项。相反,RVM 会在本地管理您的依赖项,并使用 gemset 将它们分开。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...