简体   繁体   中英

Cant run rails server on ubuntu

I am working on ruby on rails,

I have made a project using

rails new proj -d mysql

and then I type

rails server

but get this error, whats the problem

/home/mani/.rvm/gems/ruby-2.1.2/gems/execjs-2.2.1/lib/execjs/runtimes.rb:51:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
        from /home/mani/.rvm/gems/ruby-2.1.2/gems/execjs-2.2.1/lib/execjs.rb:5:in `<module:ExecJS>'
        from /home/mani/.rvm/gems/ruby-2.1.2/gems/execjs-2.2.1/lib/execjs.rb:4:in `<top (required)>'
        from /home/mani/.rvm/gems/ruby-2.1.2/gems/uglifier-2.5.3/lib/uglifier.rb:3:in `require'
        from /home/mani/.rvm/gems/ruby-2.1.2/gems/uglifier-2.5.3/lib/uglifier.rb:3:in `<top (required)>'
        from /home/mani/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.7.2/lib/bundler/runtime.rb:76:in `require'
        from /home/mani/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.7.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
        from /home/mani/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.7.2/lib/bundler/runtime.rb:72:in `each'
        from /home/mani/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.7.2/lib/bundler/runtime.rb:72:in `block in require'
        from /home/mani/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.7.2/lib/bundler/runtime.rb:61:in `each'
        from /home/mani/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.7.2/lib/bundler/runtime.rb:61:in `require'
        from /home/mani/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.7.2/lib/bundler.rb:133:in `require'
        from /home/mani/Sites/proj/config/application.rb:7:in `<top (required)>'
        from /home/mani/.rvm/gems/ruby-2.1.2/gems/railties-4.1.5/lib/rails/commands/commands_tasks.rb:79:in `require'
        from /home/mani/.rvm/gems/ruby-2.1.2/gems/railties-4.1.5/lib/rails/commands/commands_tasks.rb:79:in `block in server'
        from /home/mani/.rvm/gems/ruby-2.1.2/gems/railties-4.1.5/lib/rails/commands/commands_tasks.rb:76:in `tap'
        from /home/mani/.rvm/gems/ruby-2.1.2/gems/railties-4.1.5/lib/rails/commands/commands_tasks.rb:76:in `server'
        from /home/mani/.rvm/gems/ruby-2.1.2/gems/railties-4.1.5/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
        from /home/mani/.rvm/gems/ruby-2.1.2/gems/railties-4.1.5/lib/rails/commands.rb:17:in `<top (required)>'
        from /home/mani/Sites/proj/bin/rails:8:in `require'
        from /home/mani/Sites/proj/bin/rails:8:in `<top (required)>'
        from /home/mani/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/rails.rb:27:in `load'
        from /home/mani/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/rails.rb:27:in `call'
        from /home/mani/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/command.rb:7:in `call'
        from /home/mani/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client.rb:26:in `run'
        from /home/mani/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/bin/spring:48:in `<top (required)>'
        from /home/mani/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/binstub.rb:11:in `load'
        from /home/mani/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/binstub.rb:11:in `<top (required)>'
        from /home/mani/Sites/proj/bin/spring:16:in `require'
        from /home/mani/Sites/proj/bin/spring:16:in `<top (required)>'
        from bin/rails:3:in `load'
        from bin/rails:3:in `<main>'

Add following gems in your Gemfile :

gem 'execjs'
gem 'therubyracer'

Run bundle install and now try to start rails server rails s

You can do this on your system

sudo apt-get install nodejs

sudo apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison nodejs subversion

然后重新启动计算机。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM