在 AWS EC2 上安装 Ruby 2.0 和 Rails 4.0.0beta
Posted
技术标签:
【中文标题】在 AWS EC2 上安装 Ruby 2.0 和 Rails 4.0.0beta【英文标题】:Installing Ruby 2.0 and Rails 4.0.0beta on AWS EC2 【发布时间】:2013-03-10 05:33:42 【问题描述】:在默认的 Amazon EC2 Linux 安装 (Amazon Linux AMI 2012.09.1) 上安装 Ruby 2.0.0 和 Rails 4.0.0beta1 非常顺利。 但是 openssl 阻碍了(例如 http://railsapps.github.com/openssl-certificate-verify-failed.html)并且奇怪的是阻止 openssl 安装或导致 RubyGem 包管理器安装 rails。
如何解决这些问题?
【问题讨论】:
【参考方案1】:这是一个带有 rbenv 的变体。
SSH 进入您的全新实例:
__| __|_ )
_| ( / Amazon Linux AMI
___|\___|___|
https://aws.amazon.com/amazon-linux-ami/2012.09-release-notes/
There are 16 security update(s) out of 57 total update(s) available
Run "sudo yum update" to apply all updates.
Amazon Linux version 2013.03 is available.
[jimjh ~]$ ruby --version
ruby 1.9.3p286 (2012-10-12 revision 37165) [x86_64-linux]
模拟根并应用服务器更新:
$> sudo su -
$> yum update
安装几个包:
$> yum install git pcre pcre-devel
克隆rbenv:
$> git clone git://github.com/sstephenson/rbenv.git /usr/local/rbenv
创建以下文件:
# /etc/profile.d/rbenv.sh
export RBENV_ROOT=/usr/local/rbenv
export PATH="$RBENV_ROOT/bin:$PATH"
eval "$(rbenv init -)"
安装ruby-build:
$> . /etc/profile
$> git clone https://github.com/sstephenson/ruby-build.git /usr/local/rbenv/plugins/ruby-build
安装红宝石:
$> rbenv install 2.0.0-p195 # wait ...
$> rbenv global 2.0.0-p195
$> rbenv rehash
更新 rubygems 并安装乘客:
$> gem update --system
$> gem install bundler
$> gem install passenger
通过passenger安装nginx:
$> passenger start
在撰写本文时,乘客的最新版本是 4.0.0,它适用于 ruby 2.0.0。
弹性豆茎 如果您使用的是 Elastic Beanstalk,请停止乘客
$> sudo service passenger stop
通过将以下内容添加到 /opt/elasticbeanstalk/support/envvars.d/appenv
来初始化 rbenv
. /etc/profile.d/rbenv.sh
开始乘客
$> sudo service passenger start
【讨论】:
您可能还需要安装 openssl-devel。yum install openssl-devel
通过 rbenv 更新 ruby 后,当我使用弹性 beanstalk 部署应用程序时,没有任何反应。有人知道会发生什么吗?
我必须添加这个命令 - “yum install gcc” - 上面的说明中没有 c 编译器(或者我错过了它?)【参考方案2】:
登录您的全新实例:
[19:59:22] paul:~ $ ssh -i ~/.ssh/server.pem ec2-user@your.ip
__| __|_ )
_| ( / Amazon Linux AMI
___|\___|___|
https://aws.amazon.com/amazon-linux-ami/2012.09-release-notes/
并模拟根:
$ sudo su -
您从这里以 root 身份登录。应用服务器更新:
[root@ip-xx ~]# yum update
...
Complete!
[root@ip-xx ~]# yum groupinstall "Development Tools"
...
Install 72 Package(s)
...
Complete!
现在,这就是它与标准解决方案的不同之处。安装 RVM 但没有 ruby 的分发:
[root@ip-xx ~]# \curl -L https://get.rvm.io | bash -s stable
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 184 100 184 0 0 135 0 0:00:01 0:00:01 --:--:-- 183
100 11861 100 11861 0 0 7180 0 0:00:01 0:00:01 --:--:-- 64113
Downloading RVM from wayneeseguin branch stable
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 124 100 124 0 0 161 0 --:--:-- --:--:-- --:--:-- 185
100 1615k 100 1615k 0 0 258k 0 0:00:06 0:00:06 --:--:-- 401k
Installing RVM to /usr/local/rvm/
Creating group 'rvm'
# RVM: Shell scripts enabling management of multiple ruby environments.
# RTFM: https://rvm.io/
# HELP: http://webchat.freenode.net/?channels=rvm (#rvm on irc.freenode.net)
# Cheatsheet: http://cheat.errtheblog.com/s/rvm/
# Screencast: http://screencasts.org/episodes/how-to-use-rvm
# In case of any issues read output of 'rvm requirements' and/or 'rvm notes'
Installation of RVM in /usr/local/rvm/ is almost complete:
* First you need to add all users that will be using rvm to 'rvm' group,
and logout - login again, anyone using rvm will be operating with `umask u=rwx,g=rwx,o=rx`.
* To start using RVM you need to run `source /etc/profile.d/rvm.sh`
in all your open shell windows, in rare cases you need to reopen all shell windows.
# root,
#
# Thank you for using RVM!
# I sincerely hope that RVM helps to make your life easier and
# more enjoyable!!!
#
# ~Wayne
让我们检查一下没有安装 ruby 版本:
[root@ip-xx ~]# rvm list
rvm rubies
# No rvm rubies installed yet. Try 'rvm help install'.
现在,openssl 已经安装在系统上,但与 setup 不兼容:
[root@ip-xx ~]# openssl version
OpenSSL 1.0.0k-fips 5 Feb 2013
[root@ip-xx ~]# openssl version -d
OPENSSLDIR: "/etc/pki/tls"
尝试使用此版本安装 ruby2 将导致以下错误:
[root@ip-xx ~]# rvm install 2.0.0 -- --with-openssl-dir=/etc/pki/tls
Fetching yaml-0.1.4.tar.gz to /usr/local/rvm/archives
######################################################################## 100.0%
Extracting yaml to /usr/local/rvm/src/yaml-0.1.4
Prepare yaml in /usr/local/rvm/src/yaml-0.1.4.
Configuring yaml in /usr/local/rvm/src/yaml-0.1.4.
Compiling yaml in /usr/local/rvm/src/yaml-0.1.4.
Installing yaml to /usr/local/rvm/usr
Installing Ruby from source to: /usr/local/rvm/rubies/ruby-2.0.0-p0, this may take a while depending on your cpu(s)...
ruby-2.0.0-p0 - #downloading ruby-2.0.0-p0, this may take a while depending on your connection...
######################################################################## 100.0%
ruby-2.0.0-p0 - #extracting ruby-2.0.0-p0 to /usr/local/rvm/src/ruby-2.0.0-p0
ruby-2.0.0-p0 - #extracted to /usr/local/rvm/src/ruby-2.0.0-p0
ruby-2.0.0-p0 - #configuring
ruby-2.0.0-p0 - #compiling
ruby-2.0.0-p0 - #installing
Retrieving rubygems-2.0.3
######################################################################## 100.0%
Extracting rubygems-2.0.3 ...
Removing old Rubygems files...
Installing rubygems-2.0.3 for ruby-2.0.0-p0 ...
Error running 'env GEM_PATH=/usr/local/rvm/gems/ruby-2.0.0-p0:/usr/local/rvm/gems/ruby-2.0.0-p0@global:/usr/local/rvm/gems/ruby-2.0.0-p0:/usr/local/rvm/gems/ruby-2.0.0-p0@global GEM_HOME=/usr/local/rvm/gems/ruby-2.0.0-p0 /usr/local/rvm/rubies/ruby-2.0.0-p0/bin/ruby /usr/local/rvm/src/rubygems-2.0.3/setup.rb', please read /usr/local/rvm/log/ruby-2.0.0-p0/rubygems.install.log
Installation of rubygems did not complete successfully.
Saving wrappers to '/usr/local/rvm/bin'.
ruby-2.0.0-p0 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
cp: overwrite `/usr/local/rvm/rubies/ruby-2.0.0-p0/bin/gem'? y
cp: overwrite `/usr/local/rvm/rubies/ruby-2.0.0-p0/bin/irb'? y
cp: overwrite `/usr/local/rvm/rubies/ruby-2.0.0-p0/bin/erb'? y
cp: overwrite `/usr/local/rvm/rubies/ruby-2.0.0-p0/bin/ri'? y
cp: overwrite `/usr/local/rvm/rubies/ruby-2.0.0-p0/bin/rdoc'? y
cp: overwrite `/usr/local/rvm/rubies/ruby-2.0.0-p0/bin/testrb'? y
cp: overwrite `/usr/local/rvm/rubies/ruby-2.0.0-p0/bin/rake'? y
ruby-2.0.0-p0 - #importing default gemsets, this may take time ...
Install of ruby-2.0.0-p0 - #complete
虽然您将获得 ruby2,但“rubygems 的安装未成功完成” - 请注意警告:“Error running 'env GEM_PATH=...”
相反,我们将让 RVM 为我们安装一个 openssl 副本(请参阅 https://rvm.io/packages/openssl/)。需要 zlib-devel 包:
[root@ip-xx ~]# yum install zlib-devel
...
Installed:
zlib-devel.x86_64 0:1.2.5-7.11.amzn1
Complete!
[root@ip-xx ~]# rvm pkg install openssl
Fetching openssl-1.0.1c.tar.gz to /usr/local/rvm/archives
Extracting openssl to /usr/local/rvm/src/openssl-1.0.1c
Configuring openssl in /usr/local/rvm/src/openssl-1.0.1c.
Compiling openssl in /usr/local/rvm/src/openssl-1.0.1c.
Installing openssl to /usr/local/rvm/usr
Please note that it's required to reinstall all rubies:
rvm reinstall all --force
Updating openssl certificates
我们现在可以安装 ruby2:
[root@ip-xx ~]# rvm reinstall 2.0.0 --with-openssl-dir=/usr/local/rvm/usr
Removing /usr/local/rvm/src/ruby-2.0.0-p0...
Removing /usr/local/rvm/rubies/ruby-2.0.0-p0...
Installing Ruby from source to: /usr/local/rvm/rubies/ruby-2.0.0-p0, this may take a while depending on your cpu(s)...
ruby-2.0.0-p0 - #downloading ruby-2.0.0-p0, this may take a while depending on your connection...
ruby-2.0.0-p0 - #extracting ruby-2.0.0-p0 to /usr/local/rvm/src/ruby-2.0.0-p0
ruby-2.0.0-p0 - #extracted to /usr/local/rvm/src/ruby-2.0.0-p0
ruby-2.0.0-p0 - #configuring
ruby-2.0.0-p0 - #compiling
ruby-2.0.0-p0 - #installing
Removing old Rubygems files...
Installing rubygems-2.0.3 for ruby-2.0.0-p0 ...
Installation of rubygems completed successfully.
Saving wrappers to '/usr/local/rvm/bin'.
ruby-2.0.0-p0 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
cp: overwrite `/usr/local/rvm/rubies/ruby-2.0.0-p0/bin/gem'? y
cp: overwrite `/usr/local/rvm/rubies/ruby-2.0.0-p0/bin/irb'? y
cp: overwrite `/usr/local/rvm/rubies/ruby-2.0.0-p0/bin/erb'? y
cp: overwrite `/usr/local/rvm/rubies/ruby-2.0.0-p0/bin/ri'? y
cp: overwrite `/usr/local/rvm/rubies/ruby-2.0.0-p0/bin/rdoc'? y
cp: overwrite `/usr/local/rvm/rubies/ruby-2.0.0-p0/bin/testrb'? y
cp: overwrite `/usr/local/rvm/rubies/ruby-2.0.0-p0/bin/rake'? y
ruby-2.0.0-p0 - #importing default gemsets, this may take time ...
Install of ruby-2.0.0-p0 - #complete
Making gemset ruby-2.0.0-p0 pristine.
Making gemset ruby-2.0.0-p0@global pristine.
[root@ip-xx ~]# ruby -v
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-linux]
还有 rails4:
[root@ip-xx ~]# gem install rails -v 4.0.0beta1
...
28 gems installed
[root@ip-xx ~]# gem list
*** LOCAL GEMS ***
actionmailer (4.0.0.beta1)
actionpack (4.0.0.beta1)
activemodel (4.0.0.beta1)
activerecord (4.0.0.beta1)
activerecord-deprecated_finders (0.0.3)
activesupport (4.0.0.beta1)
arel (4.0.0.beta2)
atomic (1.0.1)
bigdecimal (1.2.0)
builder (3.1.4)
bundler (1.3.4)
erubis (2.7.0)
hike (1.2.1)
i18n (0.6.4)
io-console (0.4.2)
json (1.7.7)
mail (2.5.3)
mime-types (1.21)
minitest (4.3.2)
multi_json (1.7.1)
polyglot (0.3.3)
psych (2.0.0)
rack (1.5.2)
rack-test (0.6.2)
rails (4.0.0.beta1)
railties (4.0.0.beta1)
rake (10.0.3, 0.9.6)
rdoc (4.0.0, 3.12.2)
rubygems-bundler (1.1.1)
rvm (1.11.3.6)
sprockets (2.9.0)
sprockets-rails (2.0.0.rc3)
test-unit (2.0.0.0)
thor (0.17.0)
thread_safe (0.1.0)
tilt (1.3.6)
treetop (1.4.12)
tzinfo (0.3.37)
就是这样!
【讨论】:
其他需要考虑的事情。如果未安装 libxml2-devel 和 libxslt-devel,则 Nokogiri gem 安装失败:# yum install libxml2-devel libxslt-devel 当前版本的 Passenger 不适用于 ruby2,因此您需要安装预发布版本,如下所述:github.com/FooBarWidget/passenger/pull/71#issuecomment-14714397 刚刚使用它在 AWS EC2 实例上安装了 ruby 2.0 rails 4.0 install。像魅力一样工作。我确实必须确保安装了 ruby Racer,否则它会抱怨在尝试使用 rails 时缺少 javascript 运行时,但可以说超出了这个答案的范围 顺便说一句,'rvm pkg' 已被弃用。至少这是我在安装 openssl 的步骤时收到的消息。到我这里回复的时候,Ruby 的当前稳定版本也不再是 2.0.0 而是 2.1.0。 我今天创建了一个实例,并顺利安装了 amazon/2013.09/x86_64 和 Ruby 2.1.1,即我不必安装 rvm 的 openssl 包,只需sudo yum update
、yum groupinstall "Development Tools”
和\curl -sSL https://get.rvm.io | bash -s stable
和 rvm install ruby-2.1.1
以上是关于在 AWS EC2 上安装 Ruby 2.0 和 Rails 4.0.0beta的主要内容,如果未能解决你的问题,请参考以下文章
将Ruby on Rails项目从github上传到AWS EC2实例错误
在 Amazon OpsWorks 上使用 Ruby 2.0
使用 aws-sdk ruby gem 知道自己的实例 ID