美文网首页
Ruby on Rails的安装

Ruby on Rails的安装

作者: qin7zhen | 来源:发表于2016-12-16 20:53 被阅读721次

环境: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

相关文章

网友评论

      本文标题:Ruby on Rails的安装

      本文链接:https://www.haomeiwen.com/subject/wjznmttx.html