接下来,CentOS gcc安装
yum -y install gcc
文章分类:Ruby编程
由于ubunut系统中自带的rails和ruby版本都比较低,所以打算干掉以前的版本重新编译,遇到了N多麻烦,倒也是好事,又认识到了很多问题,明白了一些东东的含义
一 升级ruby1.8.7到1.9.2
首先下载ruby-1.9.2
- wget ftp:
-
- tar -zxvf ruby-1.9.2-p0.tar.gz
- cd ruby-1.9.2-p0
- .configure -prefix=/usr/local/ruby # 指定安装路径
- make
- make test
- make install #编译并安装
- sudo ln -s /usr/local/ruby/bin/ruby /usr/bin/ruby # 建立一个软链接
wget ftp://ftp.ruby-lang.org//pub/ruby/1.9/ruby-1.9.2-p0.tar.gz
tar -zxvf ruby-1.9.2-p0.tar.gz
cd ruby-1.9.2-p0
.configure -prefix=/usr/local/ruby # 指定安装路径
make
make test
make install #编译并安装
sudo ln -s /usr/local/ruby/bin/ruby /usr/bin/ruby # 建立一个软链接
一切顺利,不过不知道咋回事,貌似是昨天搞gem的时候,又把1.8重新弄回来了
今天,重启电脑之后,还是1.8,1.9也有,乱七八糟的,决定重来
于是,修改全部步骤,删除了usr/local/ruby 删除 usr/bin/ 下的所有ruby
重新上面的步骤(ln那条命令除外)
最后修改了一下环境变量path 编辑文件 etc/environment
- PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/ruby/bin"
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/ruby/bin"
修改完毕,重启系统,搞定
- ruby -v
- ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]
ruby -v
ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]
ruby安装完成
二 GEM的升级
运行gem命令,出错提示:依赖的ruby1.8.7 出现错误,这个是以前残留的
于是乎 /usr/bin 下的一系列gem gem1.8 gem×× 之类的全部干掉
在安装ruby1.9.2之后gem已经安装了
因为上面设置了path,gem在usr/local/ruby/bin目录下
所以删除残留的那些后运行gem依然可以
gem -v
1.3.7
但是运行gem list
出现错误
- ERROR: Loading command: list (LoadError)
- no such file to load -- zlib
- ERROR: While executing gem ... (NameError)
- uninitialized constant Gem::Commands::ListCommand
ERROR: Loading command: list (LoadError)
no such file to load -- zlib
ERROR: While executing gem ... (NameError)
uninitialized constant Gem::Commands::ListCommand
搜了一下:(http://javaeye.shaduwang.com/?www/topic/743850),说是缺少zlib
- (1)sudo apt-get install zlib1g-dev
- (2)然后到源码目录的ext/zlib下 (刚才解压的ruby1.9.2目录)
- (3)ruby extconf.rb (需要管理员权限)
- (4)make
- (5)sudo make install
(1)sudo apt-get install zlib1g-dev
(2)然后到源码目录的ext/zlib下 (刚才解压的ruby1.9.2目录)
(3)ruby extconf.rb (需要管理员权限)
(4)make
(5)sudo make install
gem list 这个可以运行了
gem install ×× 也可以运行了
补充说明:
虽然设置了环境变量的path路径,还是要建立一下软链接,要不然 执行sudo ruby或者sudo gem时还是会报错:
- sudo: ruby: command not found
sudo: ruby: command not found
所以还要建立以下软链接
- sudo ln -s /usr/local/ruby/bin/ruby /usr/bin/ruby
- sudo ln -s /usr/local/ruby/bin/gem /usr/bin/gem
sudo ln -s /usr/local/ruby/bin/ruby /usr/bin/ruby
sudo ln -s /usr/local/ruby/bin/gem /usr/bin/gem
然后执行 sudo gem -v 输出 1.3.7
三、安装rails3
运行了rails -v
bash: /usr/bin/rails:/usr/bin/ruby1.8:损坏的解释器: 没有该文件或目录
find了一下rails 发现/usr/lib/ruby/gems/1.8 目录下面有rails文件
/usr/bin/rails 便是运行时调用的rails
统统删除
执行命令 gem install rails 开始安装rails
安装完成以后运行 rails -v 没问题
但是sudo rails -v 就回提示没有这个命令
跟上面同理:sudo ln -s /usr/local/ruby/bin/rails /usr/bin/rails
sudo rails -v 也没问题了
四 其他问题
打开昨天的rails3+ruby1.8的项目,rake test出现错误
首先是一些gem的更新,造成的版本号不对应,修改之后,rake test
错误:Errors running test:units!
不知道什么错误
单独运行
- rake test:units
- !!! Missing the mysql gem. Add it to your Gemfile: gem 'mysql', '2.8.1'
rake test:units
!!! Missing the mysql gem. Add it to your Gemfile: gem 'mysql', '2.8.1'
现看了下gem list,发现还没有安装mysql 这个gem
于是 安装 mysql 的gem
sudo gem install mysql
出错,堆栈异常如下:
------------------------------------------
- Building native extensions. This could take a while...
- ERROR: Error installing mysql:
- ERROR: Failed to build gem native extension.
-
- /usr/local/ruby/bin/ruby extconf.rb
- checking for mysql_query() in -lmysqlclient... no
- checking for main() in -lm... yes
- checking for mysql_query() in -lmysqlclient... no
- checking for main() in -lz... yes
- checking for mysql_query() in -lmysqlclient... no
- checking for main() in -lsocket... no
- checking for mysql_query() in -lmysqlclient... no
- checking for main() in -lnsl... yes
- checking for mysql_query() in -lmysqlclient... no
- checking for main() in -lmygcc... no
- checking for mysql_query() in -lmysqlclient... no
- *** 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/local/ruby/bin/ruby
- --with-mysql-config
- --without-mysql-config
- --with-mysql-dir
- --without-mysql-dir
- --with-mysql-include
- --without-mysql-include=${mysql-dir}/include
- --with-mysql-lib
- --without-mysql-lib=${mysql-dir}/lib
- --with-mysqlclientlib
- --without-mysqlclientlib
- --with-mlib
- --without-mlib
- --with-mysqlclientlib
- --without-mysqlclientlib
- --with-zlib
- --without-zlib
- --with-mysqlclientlib
- --without-mysqlclientlib
- --with-socketlib
- --without-socketlib
- --with-mysqlclientlib
- --without-mysqlclientlib
- --with-nsllib
- --without-nsllib
- --with-mysqlclientlib
- --without-mysqlclientlib
- --with-mygcclib
- --without-mygcclib
- --with-mysqlclientlib
- --without-mysqlclientlib
-
-
- Gem files will remain installed in /usr/local/ruby/lib/ruby/gems/1.9.1/gems/mysql-2.8.1 for inspection.
- Results logged to /usr/local/ruby/lib/ruby/gems/1.9.1/gems/mysql-2.8.1/ext/mysql_api/gem_make.out
Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.
/usr/local/ruby/bin/ruby extconf.rb
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... no
*** 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/local/ruby/bin/ruby
--with-mysql-config
--without-mysql-config
--with-mysql-dir
--without-mysql-dir
--with-mysql-include
--without-mysql-include=${mysql-dir}/include
--with-mysql-lib
--without-mysql-lib=${mysql-dir}/lib
--with-mysqlclientlib
--without-mysqlclientlib
--with-mlib
--without-mlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-zlib
--without-zlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-socketlib
--without-socketlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-nsllib
--without-nsllib
--with-mysqlclientlib
--without-mysqlclientlib
--with-mygcclib
--without-mygcclib
--with-mysqlclientlib
--without-mysqlclientlib
Gem files will remain installed in /usr/local/ruby/lib/ruby/gems/1.9.1/gems/mysql-2.8.1 for inspection.
Results logged to /usr/local/ruby/lib/ruby/gems/1.9.1/gems/mysql-2.8.1/ext/mysql_api/gem_make.out
--------------------------------
没有安装下面这个造成的
- apt-get install libmysqlclient-dev
apt-get install libmysqlclient-dev
安装好这个,终于可以 gem install mysql了
再运行 rake test
再次出错
!!! Missing the mysql gem. Add it to your Gemfile: gem 'mysql', '2.8.1'
再看,忘了把gem 'mysql','2.8.1' 这句话放到Gemfile文件
终于……
可以运行rake test了
posted on 2011-03-05 07:44
大鸟 阅读(2487)
评论(0) 编辑 收藏 所属分类:
linux