Ruby on Rails的安裝

環境:VMware上的Ubuntu系統

不知道是否使用因為VMware的問題,這次安裝Ruby和Rails時遇到了非常多問題。在網上查詢時,也遇到了很多沒有提供解決方法的博主。因為現在我找到了解決方法,就在這總結一下我所遇到的問題吧。
首先,我終于看到這個頁面啦!!!


Ruby on Rails

一般的安裝過程

  1. 使用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中創建新的工程,并進入創建的工程。
rails new [project_name]
cd [project_name]
rails server

不一般的安裝過程(問題)

install rails中可能遇到的問題
  1. 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:in rescue 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:inblock (2 levels) in require'
from /usr/lib/ruby/vendor_ruby/bundler/runtime.rb:72:in each' from /usr/lib/ruby/vendor_ruby/bundler/runtime.rb:72:inblock in require'
from /usr/lib/ruby/vendor_ruby/bundler/runtime.rb:61:in each' from /usr/lib/ruby/vendor_ruby/bundler/runtime.rb:61:inrequire'
from /usr/lib/ruby/vendor_ruby/bundler.rb:99:in require' from /home/zhen/blog/config/application.rb:7:in<top (required)>'
from /usr/lib/ruby/vendor_ruby/rails/commands/commands_tasks.rb:78:in require' from /usr/lib/ruby/vendor_ruby/rails/commands/commands_tasks.rb:78:inblock in server'
from /usr/lib/ruby/vendor_ruby/rails/commands/commands_tasks.rb:75:in tap' from /usr/lib/ruby/vendor_ruby/rails/commands/commands_tasks.rb:75:inserver'
from /usr/lib/ruby/vendor_ruby/rails/commands/commands_tasks.rb:39:in run_command!' from /usr/lib/ruby/vendor_ruby/rails/commands.rb:17:in<top (required)>'
from bin/rails:4:in require' from bin/rails:4:in<main>'

Solutions:

sudo apt-get install nodejs
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容