接下來,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
大鳥 閱讀(2493)
評論(0) 編輯 收藏 所屬分類:
linux