请参考 http://blog.youkuaiyun.com/zzsg2005/article/details/7286036
How to install Ruby on Rails in Ubuntu 11.10
------下面是第一次安装,有问题:如重新启动后,rails执行不起来---------------------------
下载ruby1.9.3包
./configure prefix=/usr/local/ruby1930
sudo make
sudo make install
设置路径set path
sudo gedit /etc/profile
如果没有 gedit 可以 用vi编辑器
vi /etc/profile
在末尾加上 : export PATH=/usr/local/ruby193p0/bin:$PATH
说明: vi 的方法 ,光标移到最后 输入 o 在最后新增 一行。
输入 export PATH=/usr/local/ruby193p0/bin:$PATH
再按键盘的 esc ,,输入 :w 保存 文件 :q! 强制退出
安装rubygems
从rubygems.rubyforge.org上下载rubygems源码,bash代码
$tar zxvf rubygems-1.8.17
$cd rubygems-1.8.17
$sudo ruby setup.rb
提示ruby不是命令。解决:建立连接:
$sudo ln -s /usr/bin/ruby1.9.1 /usr/bin/ruby
$ ruby -v
ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]
重新执行安装命令:
acer@ubntu:~/ruby/rubygems-1.8.17$ sudo ruby setup.rb
RubyGems 1.8.17 installed
== 1.8.17 / 2012-02-17
* 2 minor enhancements:
* Add MacRuby to the list of special cases for platforms (ferrous26)
* Add a default for where to install rubygems itself
* 3 bug fixes:
* Fixed gem loading issue caused by dependencies not resolving.
* Fixed umask error when stdlib is required and unresolved dependencies exist.
* Shebang munging would only take one arg after the cmd
* Define SUCKAGE better, ie only MRI 1.9.2
* Propagate env-shebang to the pristine command if set for install.
------------------------------------------------------------------------------
RubyGems installed the following executables:
/usr/bin/gem1.9.1
acer@ubuntu:~/ruby$ gem -v
程序 'gem' 已包含在下列软件包中:
* rubygems1.8
* rubygems1.9.1
请尝试:sudo apt-get install <选定的软件包>
查看/usr/bin/下有gem1.9.1
acer@ubuntu:~/ruby$ dpkg -l rubygems1.8
期望状态=未知(u)/安装(i)/删除(r)/清除(p)/保持(h)
| 状态=未安装(n)/已安装(i)/仅存配置(c)/仅解压缩(U)/配置失败(F)/不完全安装(H)/触发器等待(W)/触发器未决(T)
|/ 错误?=(无)/须重装(R) (状态,错误:大写=故障)
||/ 名称 版本 简介
+++-==============-==============-============================================
rc rubygems1.8 1.3.7-2 package management framework for Ruby librar
acer@ubuntu:~/ruby$ sudo apt-get remove rubygems1.8
[sudo] password for acer:
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
软件包 rubygems1.8 还未安装,因而不会被卸载
升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 11 个软件包未被升级。
acer@ubuntu:~/ruby$ dpkg -l rubygems1.9.1
期望状态=未知(u)/安装(i)/删除(r)/清除(p)/保持(h)
| 状态=未安装(n)/已安装(i)/仅存配置(c)/仅解压缩(U)/配置失败(F)/不完全安装(H)/触发器等待(W)/触发器未决(T)
|/ 错误?=(无)/须重装(R) (状态,错误:大写=故障)
||/ 名称 版本 简介
+++-=================-=================-==================================================
un rubygems1.9.1 <无> (无可用描述)
acer@ubuntu:~/ruby$ sudo ln -s /usr/bin/gem1.9.1 /usr/bin/gem
acer@ubuntu:~/ruby$ gem -v
1.8.17
acer@ubuntu:~/ruby$ sudo gem install rails
Fetching: i18n-0.6.0.gem (100%)
Fetching: multi_json-1.1.0.gem (100%)
Fetching: activesupport-3.2.1.gem (100%)
Fetching: builder-3.0.0.gem (100%)
Fetching: activemodel-3.2.1.gem (100%)
Fetching: rack-1.4.1.gem (100%)
Fetching: rack-cache-1.1.gem (100%)
Fetching: rack-test-0.6.1.gem (100%)
Fetching: journey-1.0.1.gem (100%)
Fetching: hike-1.2.1.gem (100%)
Fetching: tilt-1.3.3.gem (100%)
Fetching: sprockets-2.1.2.gem (100%)
Fetching: erubis-2.7.0.gem (100%)
Fetching: actionpack-3.2.1.gem (100%)
Fetching: arel-3.0.0.gem (100%)
Fetching: tzinfo-0.3.31.gem (100%)
Fetching: activerecord-3.2.1.gem (100%)
Fetching: activeresource-3.2.1.gem (100%)
Fetching: mime-types-1.17.2.gem (100%)
Fetching: polyglot-0.3.3.gem (100%)
Fetching: treetop-1.4.10.gem (100%)
Fetching: mail-2.4.1.gem (100%)
Fetching: actionmailer-3.2.1.gem (100%)
Fetching: rake-0.9.2.2.gem (100%)
Fetching: thor-0.14.6.gem (100%)
Fetching: rack-ssl-1.3.2.gem (100%)
Fetching: json-1.6.5.gem (100%)
Building native extensions. This could take a while...
Fetching: rdoc-3.12.gem (100%)
Depending on your version of ruby, you may need to install ruby rdoc/ri data:
<= 1.8.6 : unsupported
= 1.8.7 : gem install rdoc-data; rdoc-data --install
= 1.9.1 : gem install rdoc-data; rdoc-data --install
>= 1.9.2 : nothing to do! Yay!
Fetching: railties-3.2.1.gem (100%)
Fetching: bundler-1.0.22.gem (100%)
Fetching: rails-3.2.1.gem (100%)
Successfully installed i18n-0.6.0
acer@ubuntu:~/ruby$ rails -v
Rails 3.2.1
安装mysql
sudo apt-get install mysql-server
将会安装下列额外的软件包:
libdbd-mysql-perl libdbi-perl libhtml-template-perl libnet-daemon-perl libplrpc-perl
mysql-client-5.1 mysql-server-5.1
建议安装的软件包:
libipc-sharedcache-perl tinyca mailx
下列【新】软件包将被安装:
libdbd-mysql-perl libdbi-perl libhtml-template-perl libnet-daemon-perl libplrpc-perl
mysql-client-5.1 mysql-server mysql-server-5.1
升级了 0 个软件包,新安装了 8 个软件包,要卸载 0 个软件包,有 11 个软件包未被升级。
需要下载 16.2MB 的软件包。
解压缩后会消耗掉 37.9MB 的额外空间。
您希望继续执行吗?[Y/n]y
acer@ubuntu:~/ruby$ sudo apt-get install libipc-sharedcache-perl tinyca mailx
软件包 mailx 是一个由下面的软件包提供的虚拟软件包:
mailutils 1:2.1+dfsg1-6
heirloom-mailx 12.4-2
bsd-mailx 8.1.2-0.20100314cvs-1
请您明确地选择一个来进行安装。
E: 软件包 mailx 没有可供安装的候选者
acer@ubuntu:~/ruby$ sudo apt-get install libipc-sharedcache-perl tinyca mailutils
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
将会安装下列额外的软件包:
libgsasl7 libipc-sharelite-perl libmailutils2 libntlm0 postfix
建议安装的软件包:
mailutils-mh procmail postfix-mysql postfix-pgsql postfix-ldap postfix-pcre sasl2-bin
resolvconf postfix-cdb
下列【新】软件包将被安装:
libgsasl7 libipc-sharedcache-perl libipc-sharelite-perl libmailutils2 libntlm0 mailutils
postfix tinyca
升级了 0 个软件包,新安装了 8 个软件包,要卸载 0 个软件包,有 11 个软件包未被升级。
需要下载 3,129kB 的软件包。
解压缩后会消耗掉 8,888kB 的额外空间。
您希望继续执行吗?[Y/n]y
获取:1 http://cn.archive.ubuntu.com/ubuntu/ maverick/universe libntlm0 i386 1.1-1 [18.1kB]
获取:2 http://security.ubuntu.com/ubuntu/ maverick-security/main postfix i386 2.7.1-1ubuntu0.2 [1,306kB]
获取:3 http://cn.archive.ubuntu.com/ubuntu/ maverick/universe libgsasl7 i386 1.4.4-1ubuntu1 [188kB]
获取:4 http://cn.archive.ubuntu.com/ubuntu/ maverick/main libipc-sharelite-perl i386 0.17-1+build2 [28.7kB]
获取:5 http://cn.archive.ubuntu.com/ubuntu/ maverick/main libipc-sharedcache-perl all 1.3-8 [25.3kB]
获取:6 http://cn.archive.ubuntu.com/ubuntu/ maverick/universe libmailutils2 i386 1:2.1+dfsg1-6 [1,043kB]
获取:7 http://cn.archive.ubuntu.com/ubuntu/ maverick/universe mailutils i386 1:2.1+dfsg1-6 [391kB]
获取:8 http://cn.archive.ubuntu.com/ubuntu/ maverick/universe tinyca all 0.7.5-2 [130kB]
下载 3,129kB,耗时 5分 0秒 (10.4kB/s)
正在预设定软件包 ...
选中了曾被取消选择的软件包 libntlm0。
(正在读取数据库 ... 系统当前共安装有 208870 个文件和目录。)
正在解压缩 libntlm0 (从 .../libntlm0_1.1-1_i386.deb) ...
选中了曾被取消选择的软件包 libgsasl7。
正在解压缩 libgsasl7 (从 .../libgsasl7_1.4.4-1ubuntu1_i386.deb) ...
选中了曾被取消选择的软件包 libipc-sharelite-perl。
正在解压缩 libipc-sharelite-perl (从 .../libipc-sharelite-perl_0.17-1+build2_i386.deb) ...
选中了曾被取消选择的软件包 libipc-sharedcache-perl。
正在解压缩 libipc-sharedcache-perl (从 .../libipc-sharedcache-perl_1.3-8_all.deb) ...
选中了曾被取消选择的软件包 libmailutils2。
正在解压缩 libmailutils2 (从 .../libmailutils2_1%3a2.1+dfsg1-6_i386.deb) ...
选中了曾被取消选择的软件包 postfix。
正在解压缩 postfix (从 .../postfix_2.7.1-1ubuntu0.2_i386.deb) ...
选中了曾被取消选择的软件包 mailutils。
正在解压缩 mailutils (从 .../mailutils_1%3a2.1+dfsg1-6_i386.deb) ...
选中了曾被取消选择的软件包 tinyca。
正在解压缩 tinyca (从 .../tinyca_0.7.5-2_all.deb) ...
正在处理用于 man-db 的触发器...
正在处理用于 ureadahead 的触发器...
正在处理用于 ufw 的触发器...
正在设置 libntlm0 (1.1-1) ...
正在设置 libgsasl7 (1.4.4-1ubuntu1) ...
正在设置 libipc-sharelite-perl (0.17-1+build2) ...
正在设置 libipc-sharedcache-perl (1.3-8) ...
正在设置 libmailutils2 (1:2.1+dfsg1-6) ...
正在设置 postfix (2.7.1-1ubuntu0.2) ...
正在添加组"postfix" (GID 126)...
完成。
正在添加系统用户"postfix" (UID 117)...
正在将新用户"postfix" (UID 117)添加到组"postfix"...
无法创建主目录"/var/spool/postfix"
Creating /etc/postfix/dynamicmaps.cf
Adding tcp map entry to /etc/postfix/dynamicmaps.cf
正在添加组"postdrop" (GID 127)...
完成。
/etc/aliases does not exist, creating it.
Postfix was not set up. Start with
cp /usr/share/postfix/main.cf.debian /etc/postfix/main.cf
. If you need to make changes, edit
/etc/postfix/main.cf (and others) as needed. To view Postfix configuration
values, see postconf(1).
After modifying main.cf, be sure to run '/etc/init.d/postfix reload'.
正在设置 mailutils (1:2.1+dfsg1-6) ...
update-alternatives: 使用 /usr/bin/frm.mailutils 来提供 /usr/bin/frm (frm),于 自动模式 中。
update-alternatives: 使用 /usr/bin/from.mailutils 来提供 /usr/bin/from (from),于 自动模式 中。
update-alternatives: 使用 /usr/bin/messages.mailutils 来提供 /usr/bin/messages (messages),于 自动模式 中。
update-alternatives: 使用 /usr/bin/movemail.mailutils 来提供 /usr/bin/movemail (movemail),于 自动模式 中。
update-alternatives: 使用 /usr/bin/readmsg.mailutils 来提供 /usr/bin/readmsg (readmsg),于 自动模式 中。
update-alternatives: 使用 /usr/bin/dotlock.mailutils 来提供 /usr/bin/dotlock (dotlock),于 自动模式 中。
update-alternatives: 使用 /usr/bin/mail.mailutils 来提供 /usr/bin/mailx (mailx),于 自动模式 中。
正在设置 tinyca (0.7.5-2) ...
正在处理用于 libc-bin 的触发器...
ldconfig deferred processing now taking place
acer@ubuntu:~/ruby$ rails new demo
create
create README.rdoc
create Rakefile
create config.ru
create .gitignore
create Gemfile
create app
create app/assets/images/rails.png
create app/assets/javascripts/application.js
create app/assets/stylesheets/application.css
create app/controllers/application_controller.rb
create app/helpers/application_helper.rb
create app/mailers
create app/models
create app/views/layouts/application.html.erb
create app/mailers/.gitkeep
create app/models/.gitkeep
create config
create config/routes.rb
create config/application.rb
create config/environment.rb
create config/environments
create config/environments/development.rb
create config/environments/production.rb
create config/environments/test.rb
create config/initializers
create config/initializers/backtrace_silencers.rb
create config/initializers/inflections.rb
create config/initializers/mime_types.rb
create config/initializers/secret_token.rb
create config/initializers/session_store.rb
create config/initializers/wrap_parameters.rb
create config/locales
create config/locales/en.yml
create config/boot.rb
create config/database.yml
create db
create db/seeds.rb
create doc
create doc/README_FOR_APP
create lib
create lib/tasks
create lib/tasks/.gitkeep
create lib/assets
create lib/assets/.gitkeep
create log
create log/.gitkeep
create public
create public/404.html
create public/422.html
create public/500.html
create public/favicon.ico
create public/index.html
create public/robots.txt
create script
create script/rails
create test/fixtures
create test/fixtures/.gitkeep
create test/functional
create test/functional/.gitkeep
create test/integration
create test/integration/.gitkeep
create test/unit
create test/unit/.gitkeep
create test/performance/browsing_test.rb
create test/test_helper.rb
create tmp/cache
create tmp/cache/assets
create vendor/assets/javascripts
create vendor/assets/javascripts/.gitkeep
create vendor/assets/stylesheets
create vendor/assets/stylesheets/.gitkeep
create vendor/plugins
create vendor/plugins/.gitkeep
run bundle install
Fetching source index for https://rubygems.org/
Using rake (0.9.2.2)
Using i18n (0.6.0)
Using multi_json (1.1.0)
Using activesupport (3.2.1)
Using builder (3.0.0)
Using activemodel (3.2.1)
Using erubis (2.7.0)
Using journey (1.0.1)
Using rack (1.4.1)
Using rack-cache (1.1)
Using rack-test (0.6.1)
Using hike (1.2.1)
Using tilt (1.3.3)
Using sprockets (2.1.2)
Using actionpack (3.2.1)
Using mime-types (1.17.2)
Using polyglot (0.3.3)
Using treetop (1.4.10)
Using mail (2.4.1)
Using actionmailer (3.2.1)
Using arel (3.0.0)
Using tzinfo (0.3.31)
Using activerecord (3.2.1)
Using activeresource (3.2.1)
Using bundler (1.0.22)
Installing coffee-script-source (1.2.0)
Installing execjs (1.3.0)
Installing coffee-script (2.2.0)
Using rack-ssl (1.3.2)
Using json (1.6.5)
Using rdoc (3.12)
Using thor (0.14.6)
Using railties (3.2.1)
Installing coffee-rails (3.2.2)
Installing jquery-rails (2.0.0)
Using rails (3.2.1)
Installing sass (3.1.15)
Installing sass-rails (3.2.4)
Installing sqlite3 (1.3.5) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/usr/bin/ruby1.9.1 extconf.rb
checking for sqlite3.h... no
sqlite3.h is missing. Try 'port install sqlite3 +universal'
or 'yum install sqlite-devel' and check your shared library search path (the
location where your sqlite3 shared library is located).
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/bin/ruby1.9.1
--with-sqlite3-dir
--without-sqlite3-dir
--with-sqlite3-include
--without-sqlite3-include=${sqlite3-dir}/include
--with-sqlite3-lib
--without-sqlite3-lib=${sqlite3-dir}/lib
--enable-local
--disable-local
Gem files will remain installed in /home/acer/.bundler/tmp/20720/gems/sqlite3-1.3.5 for inspection.
Results logged to /home/acer/.bundler/tmp/20720/gems/sqlite3-1.3.5/ext/sqlite3/gem_make.out
An error occured while installing sqlite3 (1.3.5), and Bundler cannot continue.
Make sure that `gem install sqlite3 -v '1.3.5'` succeeds before bundling.
哦,系统中没有安装sqlite3.[和mysql一样,要在rails项目构建前先安装环境]
acer@ubuntu:~$ sudo apt-get install libsqlite3-dev
正在设置 libsqlite3-dev (3.7.2-1) ...
acer@ubuntu:~$ sudo ruby /usr/lib/ruby/gems/1.9.1/gems/sqlite3-1.3.5/setup.rb
acer@ubuntu:~$ rails new demo
。。。
Installing sqlite3 (1.3.5) with native extensions
Installing uglifier (1.2.3)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
acer@ubuntu:~$ sudo apt-get install imagemagick
...正在设置 imagemagick (7:6.6.2.6-1ubuntu1.1) ...
正在设置 libcdt4 (2.26.3-4) ...
正在设置 libgraph4 (2.26.3-4) ...
正在设置 libpathplan4 (2.26.3-4) ...
正在设置 libxdot4 (2.26.3-4) ...
正在设置 libgvc5 (2.26.3-4) ...
正在设置 libmagickcore3-extra (7:6.6.2.6-1ubuntu1.1) ...