简体   繁体   English

本地的宝石库? 安装没有“宝石”的红宝石宝石?

[英]Local gem repository? Install a ruby gem without 'gem'?

Is it possibile to have something like a 'local' gem repository for Ruby? 像Ruby这样的“本地” gem存储库有可能吗?

I'm working on a custom Linux distribution without admin rights. 我正在开发没有管理员权限的自定义Linux发行版。 Ruby is installed on the machine (v.1.8.7) but apparently no 'gem' or 'bundle' or whatever are installed. Ruby已安装在计算机(v.1.8.7)上,但显然未安装'gem'或'bundle'或任何其他工具。 I need to use some Ruby gems like Nokogiri. 我需要使用一些像Nokogiri这样的Ruby宝石。

Is it possible to use Ruby gems without installing them through gem install ? 是否可以在不通过gem install进行安装的情况下使用Ruby gem?

Yes. 是。 Any gem can be used standalone. 任何宝石都可以独立使用。 You just have to either download the source from github, or download the gem and extract its contents manually. 您只需要从github下载源代码,或者下载gem并手动提取其内容即可。

After you've done that you have to add the lib folder of the gem into the load path ( $: ) of Ruby. 完成之后,必须将gem的lib文件夹添加到Ruby的加载路径( $: :)中。 For example: 例如:

$:.unshift(File.expand_path("nokogiri-1.6.1/lib"))
require 'nokogiri'

Assuming you are running Ruby in the current directory and the Nokogiri source is in the folder nokogiri-1.6.1 . 假设您在当前目录中运行Ruby,并且Nokogiri源位于文件夹nokogiri-1.6.1

But remember that first you have to do the same with all Nokogiri prerequisites. 但是请记住,首先必须对所有Nokogiri必备条件进行相同的操作。 Ie all the libraries Nokogiri depends on. 即Nokogiri依赖的所有库。

Another option, which is what I would do, is to install RubyGems in your home directory. 我会做的另一种选择是在主目录中安装RubyGems。 That can get a little bit tricky though, but it's possible by downloading the RubyGems package and running something like: 虽然这可能会有些棘手,但是可以通过下载RubyGems包并运行类似的命令来实现:

ruby setup.rb --prefix=/home/my_user_name/rubygems

Then you need to set up the ENV variables GEM_HOME and GEM_PATH to point to a location in your home directory where you want all your gems to be installed. 然后,您需要设置ENV变量GEM_HOMEGEM_PATH指向您要安装所有gem的主目录中的位置。 See " What's the difference between GEM_HOME and GEM_PATH? " for a description of what they do. 请参阅“ GEM_HOME和GEM_PATH有什么区别? ”以获取它们的作用说明。

You will also need to add something like /home/my_user_name/rubygems/bin to your PATH so that the gem command can be found by the shell. 您还需要在PATH添加/home/my_user_name/rubygems/bin ,以便shell可以找到gem命令。

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

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