新手问题 rails 的启动问提。

yirolhao · 2016年11月18日 · 最后由 rubyyjc520 回复于 2018年09月26日 · 3034 次阅读

rails new web

rails s

然后出错

/home/yirol/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/lib/bundler/runtime.rb:94:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'uglifier'. (Bundler::GemRequireError) Gem Load Error is: Could not find a JavaScript runtime. See https://github.com/rails/execjs for a list of available runtimes. Backtrace for gem load error is:

修改 Gemfile 文件,将 gem 'therubyracer', platforms: :ruby 的注释取消,然后出现如下错误

=> Booting Puma => Rails 5.0.0.1 application starting in development on http://localhost:3000 => Run rails server -h for more startup options Puma starting in single mode...

  • Version 3.6.0 (ruby 2.3.1-p112), codename: Sleepy Sunday Serenity
  • Min threads: 5, max threads: 5
  • Environment: development
  • Listening on tcp://localhost:3001 Exiting /home/yirol/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.6.0/lib/puma/binder.rb:266:in `initialize': Cannot assign requested address - bind(2) for "::1" port 3001 (Errno::EADDRNOTAVAIL)

在网上找到的运行命令:rails server -e development -b 0.0.0.0 -p 3000

这样就能够成功,但是我想知道怎么解决,可以用 rails s

缺少 js runtime,安装 nodejs

Could not find a JavaScript runtime

#1 楼 @firebroo 安装了,没用啊。 node --version # => v7.1.0

你是怎么装的?我记得用 nvm 装的 node,不可以。

#5 楼 @yunshang 就是用 nvm 装的,应该怎么装?

#6 楼 @yirolhao sudo apt-get install -y nodejs

#8 楼 @yirolhao sudo yum install nodejs 这样?

#9 楼 @yunshang

已安装: nodejs.x86_64 1:6.9.1-1.el7
作为依赖被安装: libicu.x86_64 0:50.1.2-15.el7 libuv.x86_64 1:1.9.1-1.el7
npm.x86_64 1:3.10.8-1.6.9.1.1.el7
完毕!

还是不行。。

#11 楼 @yunshang 我的是 rails server 命令失败了,还是上面那个第二个错误。

#13 楼 @yunshang 把那个 puma 注释掉,可以启动,但是没办法外网访问。那个绑定 IP 可以外网访问。

rails server -e development -b 0.0.0.0 -p 3000

我用的是阿里云。

::1 ipv6 解决办法就是禁用掉 ipv6

ubutnu

vim /etc/sysctl.conf
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1

sudo sysctl -p

#15 楼 @flowerwrong 禁用应该可以解决,我用那条复杂的命令算了,怕以后出现其他问题。。

17 楼 已删除

👍 我 yum 安装 nodejs 就 ok 了 😁

需要 登录 后方可回复, 如果你还没有账号请 注册新账号