about rubygems install-阿里云开发者社区

开发者社区> 余二五> 正文

about rubygems install

简介:
+关注继续查看

3. Installing RubyGems

3.1 Installing RubyGems

Get it from RubyForge ([url]http://rubyforge.org/frs/?group_id=126[/url]) and run (as root, if appropriate and necessary)
ruby setup.rb
It’s easy. It installs the required library files and the gem command. This command gives us the power to do everything else in this document, except distribute gems (for now!).
Debian Linux: Debian does not automatically include all the standard Ruby libararies in the basic Ruby package. As a result, you may need to ’’apt-get’’ libyaml-ruby and libzlib-ruby before you can install rubygems.

3.2 Installing RubyGems in a User Directory

If a user does not have access to the standard installation location (typically /usr/local/lib/ruby), then they have the option of installing RubyGems in a alternate location.
Note that if you can’t install RubyGems in the standard location, then you probably can’t install gems in the standard gem repository location either. You need to specifiy a non-standard gem repository location via the GEM_HOME environment variable.
Use the following to install RubyGems in a user directory (here called /home/mystuff) with a repository named /home/mygemrepository):
$ export GEM_HOME=/home/mygemrepository
$ ruby setup.rb config --prefix=/home/mystuff
$ ruby setup.rb setup
$ ruby setup.rb install
Notes:
  1. The export command is ksh specific. Use the appropriate command for your OS. For example windows users would probably say:
    set GEM_HOME=/home/mygemrepository
  2. Make sure you add /home/mystuff/bin to your path so that the gem command can be found.
  3. Make sure you add the GEM_HOME setup to your profile, so that RubyGems can find the location of your gem repository.
  4. If you want the gem repository to reside inside the install directory, we recommend setting GEM_HOME prefix_dir/gems. (where prefix_dir is given as the valud of --prefix in the config step)

3.3 Updating RubyGems

Modern Versions of RubyGems

If your RubyGems version is 0.8.5 or later, you can upgrade to the latest version with:
gem update --system
Don’t forget to use sudo if your system requires root access to install ruby libraries.

Prior to RubyGems 0.8.5

If you current version of RubyGems is prior to version 0.8.5, then use the following commands:
gem install rubygems-update
update_rubygems

Manual Upgrades

Download the latest RubyGems tar or zip file and following the instructions for Installing RubyGems.

3.4 Post-install -- Setting Up the RubyGems Environment

Now that you have RubyGems installed, you should be ready to run applications using gems, right?
Well, almost.
You have one more decision to make: How to let Ruby programs know to use the gems repository.
You see, because the of versioned nature of the gems repository, RubyGems doesn’t store the library files directly in standard library search path. It adds the necessary gem packages to the library seach path as needed at run time.
This means that RubyGems must be loaded before any gem libraries are accessable.

The Hard Way

The most direct way to make RubyGems available is to just require it in the source code:
   require 'rubygems'
require 'some_gem_library'
# ...
The big problem with this approach is that you don’t want to make this change to every single Ruby program you download! While ok for quick scripts you write yourself, this is not the way to go.

Using the -rubygems Command Line Option

To avoid modifying all the Ruby programs you install, you could tell the ruby interpreter to preload ruby gems before running other software. You can easily do this by giving the ruby command a -rubygems option each time you run a program.
ruby -rubygems my_program_that_uses_gems
This works, and avoids changing installed software, but is a pain to type all the time. Fortunately there is another option.

Using RUBYOPT

By setting the RUBYOPT environment variable to the value rubygems, you tell Ruby to load RubyGems every time it starts up. This is similar to the -rubygems options above, but you only have to specify this once (rather than each time you run a Ruby script).
Unix users will want to put the following line in their .profile (or equivalent):
export RUBYOPT=rubygems
Windows users will want to set the RUBYOPT environment variable using the appropriate sysetm utility. (On XP you can find it under Settings / Control Panel / System. Click the advanced tab and then the “Environment Variables” button near the bottom. Note that the one-click installer will set up RUBYOPT for you automatically (unless you request it not be done).

The Future

The need to preload the RubyGems software is one of the biggest drawbacks to RubyGems’ versioned software approach. The RubyGems team is investigating ways of making this issue much less onerous.
In the meantime, enjoy RubyGems.




本文转自 fsjoy1983 51CTO博客,原文链接:http://blog.51cto.com/fsjoy/63910,如需转载请自行联系原作者

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
使用NAT网关轻松为单台云服务器设置多个公网IP
在应用中,有时会遇到用户询问如何使单台云服务器具备多个公网IP的问题。 具体如何操作呢,有了NAT网关这个也不是难题。
26768 0
阿里云服务器怎么设置密码?怎么停机?怎么重启服务器?
如果在创建实例时没有设置密码,或者密码丢失,您可以在控制台上重新设置实例的登录密码。本文仅描述如何在 ECS 管理控制台上修改实例登录密码。
9998 0
使用SSH远程登录阿里云ECS服务器
远程连接服务器以及配置环境
2496 0
阿里云服务器端口号设置
阿里云服务器初级使用者可能面临的问题之一. 使用tomcat或者其他服务器软件设置端口号后,比如 一些不是默认的, mysql的 3306, mssql的1433,有时候打不开网页, 原因是没有在ecs安全组去设置这个端口号. 解决: 点击ecs下网络和安全下的安全组 在弹出的安全组中,如果没有就新建安全组,然后点击配置规则 最后如上图点击添加...或快速创建.   have fun!  将编程看作是一门艺术,而不单单是个技术。
10880 0
阿里云服务器安全组设置内网互通的方法
虽然0.0.0.0/0使用非常方便,但是发现很多同学使用它来做内网互通,这是有安全风险的,实例有可能会在经典网络被内网IP访问到。下面介绍一下四种安全的内网互联设置方法。 购买前请先:领取阿里云幸运券,有很多优惠,可到下文中领取。
11808 0
阿里云服务器如何登录?阿里云服务器的三种登录方法
购买阿里云ECS云服务器后如何登录?场景不同,阿里云优惠总结大概有三种登录方式: 登录到ECS云服务器控制台 在ECS云服务器控制台用户可以更改密码、更换系.
13793 0
windows server 2008阿里云ECS服务器安全设置
最近我们Sinesafe安全公司在为客户使用阿里云ecs服务器做安全的过程中,发现服务器基础安全性都没有做。为了为站长们提供更加有效的安全基础解决方案,我们Sinesafe将对阿里云服务器win2008 系统进行基础安全部署实战过程! 比较重要的几部分 1.
9146 0
腾讯云服务器 设置ngxin + fastdfs +tomcat 开机自启动
在tomcat中新建一个可以启动的 .sh 脚本文件 /usr/local/tomcat7/bin/ export JAVA_HOME=/usr/local/java/jdk7 export PATH=$JAVA_HOME/bin/:$PATH export CLASSPATH=.
4650 0
阿里云服务器ECS登录用户名是什么?系统不同默认账号也不同
阿里云服务器Windows系统默认用户名administrator,Linux镜像服务器用户名root
4467 0
+关注
20382
文章
0
问答
文章排行榜
最热
最新
相关电子书
更多
《2021云上架构与运维峰会演讲合集》
立即下载
《零基础CSS入门教程》
立即下载
《零基础HTML入门教程》
立即下载