環(huán)境:VMware上的Ubuntu系統(tǒng)
不知道是否使用因?yàn)閂Mware的問題纲辽,這次安裝Ruby和Rails時(shí)遇到了非常多問題递惋。在網(wǎng)上查詢時(shí)坑匠,也遇到了很多沒有提供解決方法的博主砚哆。因?yàn)楝F(xiàn)在我找到了解決方法惊来,就在這總結(jié)一下我所遇到的問題吧。
首先桐腌,我終于看到這個(gè)頁面啦V粝浴!案站!
一般的安裝過程
- 使用
apt-get
安裝最新版本的ruby
sudo apt-get update
sudo apt-get install ruby2.3
- 使用
apt-get
安裝ruby的依賴包
sudo apt-get install ruby2.3-dev
- 使用
gem
安裝Rails
sudo gem install rails
- 安裝Rails的依賴包
sudo apt-get install libsqlite3-dev
sudo gem install sqlite3
bundle install
sudo apt install ruby-railties
- 在Rails中創(chuàng)建新的工程躬审,并進(jìn)入創(chuàng)建的工程。
rails new [project_name]
cd [project_name]
- 啟動(dòng)server蟆盐,測試Rails是否安裝成功承边。在瀏覽器中訪問http://localhost:3000。
rails server
不一般的安裝過程(問題)
- Error: Can not find 'bundle'
'bundle' is currently not installed.
Solutions:
sudo apt install ruby-bundler
- Error:
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
Installing nokogiri 1.6.8.1 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /tmp/bundler20161216-4008-jpesjqnokogiri-1.6.8.1/gems/nokogiri-1.6.8.1/ext/nokogiri
/usr/bin/ruby2.3 -r ./siteconf20161216-4008-1uempjz.rb extconf.rb
checking if the C compiler accepts ... yes
Building nokogiri using packaged libraries.
Using mini_portile version 2.1.0
checking for gzdopen() in -lz... no
zlib is missing; necessary for building libxml2
*** 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:
...
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/tmp/bundler20161216-4008-jpesjqnokogiri-1.6.8.1/extensions/x86_64-linux/2.3.0/nokogiri-1.6.8.1/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /tmp/bundler20161216-4008-jpesjqnokogiri-1.6.8.1/gems/nokogiri-1.6.8.1 for inspection.
Results logged to /tmp/bundler20161216-4008-jpesjqnokogiri-1.6.8.1/extensions/x86_64-linux/2.3.0/nokogiri-1.6.8.1/gem_make.out
An error occurred while installing nokogiri (1.6.8.1), and Bundler cannot continue.
Solutions:
sudo gem install nokogiri
- Error:
ERROR: Error installing nokogiri:
$ sudo gem install nokogiri
Building native extensions. This could take a while...
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
current directory: /var/lib/gems/2.3.0/gems/nokogiri-1.6.8.1/ext/nokogiri
/usr/bin/ruby2.3 -r ./siteconf20161216-4223-jip6ko.rb extconf.rb
checking if the C compiler accepts ... yes
Building nokogiri using packaged libraries.
Using mini_portile version 2.1.0
checking for gzdopen() in -lz... no
zlib is missing; necessary for building libxml2
*** 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:
...
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/nokogiri-1.6.8.1/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /var/lib/gems/2.3.0/gems/nokogiri-1.6.8.1 for inspection.
Results logged to /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/nokogiri-1.6.8.1/gem_make.out
Solutions:
sudo apt-get install libxslt-dev libxml2-dev
sudo apt-get install build-essential patch
sudo apt-get install zlib1g-dev liblzma-dev
- Error:
Bundler::GemRequireError`
There was an error while trying to load the gem 'uglifier'
$ rails server
/usr/lib/ruby/vendor_ruby/bundler/runtime.rb:80:inrescue in block (2 levels) in require': There was an error while trying to load the gem 'uglifier'. (Bundler::GemRequireError) from /usr/lib/ruby/vendor_ruby/bundler/runtime.rb:76:in
block (2 levels) in require'
from /usr/lib/ruby/vendor_ruby/bundler/runtime.rb:72:ineach' from /usr/lib/ruby/vendor_ruby/bundler/runtime.rb:72:in
block in require'
from /usr/lib/ruby/vendor_ruby/bundler/runtime.rb:61:ineach' from /usr/lib/ruby/vendor_ruby/bundler/runtime.rb:61:in
require'
from /usr/lib/ruby/vendor_ruby/bundler.rb:99:inrequire' from /home/zhen/blog/config/application.rb:7:in
<top (required)>'
from /usr/lib/ruby/vendor_ruby/rails/commands/commands_tasks.rb:78:inrequire' from /usr/lib/ruby/vendor_ruby/rails/commands/commands_tasks.rb:78:in
block in server'
from /usr/lib/ruby/vendor_ruby/rails/commands/commands_tasks.rb:75:intap' from /usr/lib/ruby/vendor_ruby/rails/commands/commands_tasks.rb:75:in
server'
from /usr/lib/ruby/vendor_ruby/rails/commands/commands_tasks.rb:39:inrun_command!' from /usr/lib/ruby/vendor_ruby/rails/commands.rb:17:in
<top (required)>'
from bin/rails:4:inrequire' from bin/rails:4:in
<main>'
Solutions:
sudo apt-get install nodejs