环境:VMware上的Ubuntu系统
不知道是否使用因为VMware的问题,这次安装Ruby和Rails时遇到了非常多问题。在网上查询时,也遇到了很多没有提供解决方法的博主。因为现在我找到了解决方法,就在这总结一下我所遇到的问题吧。
首先,我终于看到这个页面啦!!!
一般的安装过程
- 使用
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]
- 启动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