如何在 Ubuntu 10.10 上安装 Ruby on Rails 3.0? [英] How to install Ruby on Rails 3.0 on Ubuntu 10.10?
问题描述
安装 Ruby 和 Ruby Gems 后:
After installing Ruby and Ruby Gems:
$ sudo apt-get install ruby rubygems
...
$ ruby -v
ruby 1.8.7 (2010-06-23 patchlevel 299) [i686-linux]
$ gem -v
1.3.7
如果我尝试安装 Rails,我会收到一个错误,即使它似乎只是文档,rails
也没有安装:
If I try to install Rails I get an error, and even though it seems to be the documentation only, rails
isn't installed:
$ sudo gem install rails
...
Successfully installed rails-3.0.1
24 gems installed
...
Installing ri documentation for builder-2.1.2...
ERROR: While generating documentation for builder-2.1.2
... MESSAGE: Unhandled special: Special: type=17, text="<!-- HI -->"
... RDOC args: --ri --op /var/lib/gems/1.8/doc/builder-2.1.2/ri --title Builder -- Easy XML Building --main README --line-numbers --quiet lib CHANGES Rakefile README doc/releases/builder-1.2.4.rdoc doc/releases/builder-2.0.0.rdoc doc/releases/builder-2.1.1.rdoc --title builder-2.1.2 Documentation
(continuing with the rest of the installation)
...
Installing ri documentation for rails-3.0.1...
File not found: lib
$ rails -v
The program 'rails' is currently not installed. You can install it by typing:
sudo apt-get install rails
Ubuntu 存储库只有 Rails 2.3.5,所以这不是一个选项.
Ubuntu repositories only have Rails 2.3.5 so that isn't an option.
如何让 Rails 正确安装?
How do I get Rails to install properly?
更新:我尝试了以下,这次没有错误,但仍然没有成功:
Update: I tried the following, no error this time, but still no success:
$ sudo gem install rails --no-rdoc --no-ri
Successfully installed rails-3.0.1
1 gem installed
$ rails -v
The program 'rails' is currently not installed...
更新 2: 所以,感谢 Maran 和 Jörg,我现在知道问题不在于未安装 rails
,而是未将其添加到 路径代码>.这可以通过将以下内容添加到
~/.bashrc
来解决:
Update 2: So, thanks to Maran and Jörg, I now know the problem is not that rails
isn't installed, but it's not added to the PATH
. This can be fixed by adding the following to ~/.bashrc
:
export PATH=/var/lib/gems/1.8/bin:$PATH
这又提出了一个问题:应该将什么添加到 PATH
中?大概是 apt-get install rubygems
?还有什么可能被破坏?
That raises a further question: What should have added that to the PATH
? Presumably the apt-get install rubygems
? And what else may be broken?
推荐答案
好吧,我犹豫是否使用 rvm
因为它似乎旨在解决我不打算遇到的问题(多个 ruby版本?来吧,我只是想玩 Rails...)并且从源代码安装通常是我想避免的...
Ok, I hesitated to use rvm
as it seemed to be aimed at solving problems I didn't intend to have (multiple ruby versions? c'mon, I just want to play with rails...) and installing from source is generally something I want to avoid...
无论如何,我放弃并跟随 http://rvm.beginrescueend.com/rvm/安装/
Anyway, I gave in and followed along with http://rvm.beginrescueend.com/rvm/install/
$ bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
然后(主要由上面的输出建议,但我需要添加 libmysqlclient-dev
):
Then (mostly suggested by the output of the above, but I needed to add libmysqlclient-dev
):
$ sudo aptitude install build-essential bison openssl libreadline5
libreadline5-dev curl git zlib1g zlib1g-dev
libssl-dev libsqlite3-0 libsqlite3-dev sqlite3
libxml2-dev libmysqlclient-dev
然后我根据需要编辑了我的 .bashrc
并打开了一个新终端.
Then I edited my .bashrc
as required and opened a new terminal.
$ rvm install 1.9.2
$ rvm --default use 1.9.2
$ ruby -v
ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]
$ gem install rails
$ rails -v
Rails 3.0.1
创建一个新项目后,我还有一些事情要做才能让它工作:
After creating a new project, I still had a few things to do to make it work:
$ rails new myproject --database=mysql
$ cd myproject
$ emacs config/database.yml # set passwords
$ bundle install
$ rake db:create
$ rails server
最后,一切似乎都奏效了.我希望对其他人有所帮助,这当然不是一个特别令人愉快的框架介绍.我已经对我实际输入的命令进行了重新排序,以避免对跟随的任何人进行双重处理.
And finally it all seems to be working. I hope that helps someone else, it certainly wasn't a particularly pleasant intro to a framework. I've reordered the commands I actually entered to avoid double handling for anyone following along.
这篇关于如何在 Ubuntu 10.10 上安装 Ruby on Rails 3.0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!