我正在尝试运行我下载的rails服务器示例。但是,我收到了权限错误:
我跑:
rails server
我明白了:
=> Booting Puma
=> Rails 4.2.4 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
/usr/share/rvm/rubies/ruby-2.1.7/lib/ruby/2.1.0/fileutils.rb:250:in `mkdir': Permission denied @ dir_s_mkdir - /home/username/web-app/tmp (Errno::EACCES)
from /usr/share/rvm/rubies/ruby-2.1.7/lib/ruby/2.1.0/fileutils.rb:250:in `fu_mkdir'
from /usr/share/rvm/rubies/ruby-2.1.7/lib/ruby/2.1.0/fileutils.rb:224:in `block (2 levels) in mkdir_p'
from /usr/share/rvm/rubies/ruby-2.1.7/lib/ruby/2.1.0/fileutils.rb:222:in `reverse_each'
from /usr/share/rvm/rubies/ruby-2.1.7/lib/ruby/2.1.0/fileutils.rb:222:in `block in mkdir_p'
from /usr/share/rvm/rubies/ruby-2.1.7/lib/ruby/2.1.0/fileutils.rb:208:in `each'
from /usr/share/rvm/rubies/ruby-2.1.7/lib/ruby/2.1.0/fileutils.rb:208:in `mkdir_p'
from /home/username/.rvm/gems/ruby-2.1.7/gems/railties-4.2.4/lib/rails/commands/server.rb:134:in `block in create_tmp_directories'
from /home/username/.rvm/gems/ruby-2.1.7/gems/railties-4.2.4/lib/rails/commands/server.rb:133:in `each'
from /home/username/.rvm/gems/ruby-2.1.7/gems/railties-4.2.4/lib/rails/commands/server.rb:133:in `create_tmp_directories'
from /home/username/.rvm/gems/ruby-2.1.7/gems/railties-4.2.4/lib/rails/commands/server.rb:77:in `start'
from /home/username/.rvm/gems/ruby-2.1.7/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:80:in `block in server'
from /home/username/.rvm/gems/ruby-2.1.7/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:75:in `tap'
from /home/username/.rvm/gems/ruby-2.1.7/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:75:in `server'
from /home/username/.rvm/gems/ruby-2.1.7/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /home/username/.rvm/gems/ruby-2.1.7/gems/railties-4.2.4/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
我发现这是一个权限错误:
sudo rails server
但我只收到此错误
Your Ruby version is 1.9.3, but your Gemfile specified 2.1.7
当root用户似乎使用不同版本的ruby时,如何克服权限问题?
编辑1:
ruby --version
返回:
ruby 2.1.7p400 (2015-08-18 revision 51632) [i686-linux]
编辑2:
sudo ruby --version
返回:
ruby 1.9.3p484 (2013-11-22 revision 43786) [i686-linux]
编辑3:
我的web-app目录中没有tmp文件。当我输入ls -la
时,我得到:
drwxr-xr-x 12 root root 4096 Nov 15 10:32 .
drwxr-xr-x 31 username username 4096 Nov 17 04:23 ..
drwxr-xr-x 10 root root 4096 Nov 15 10:32 app
drwxr-xr-x 2 root root 4096 Nov 15 10:32 bin
-rw-r--r-- 1 root root 126 Nov 15 10:32 browserslist
-rw-r--r-- 1 root root 363 Nov 15 10:32 Capfile
drwxr-xr-x 6 root root 4096 Nov 15 10:32 config
-rw-r--r-- 1 root root 153 Nov 15 10:32 config.ru
drwxr-xr-x 3 root root 4096 Nov 15 10:32 db
-rw-r--r-- 1 root root 1301 Nov 15 10:32 Gemfile
-rw-r--r-- 1 root root 10953 Nov 15 10:32 Gemfile.lock
drwxr-xr-x 8 root root 4096 Nov 15 10:32 .git
-rw-r--r-- 1 root root 470 Nov 15 10:32 .gitignore
drwxr-xr-x 4 root root 4096 Nov 15 10:32 lib
drwxr-xr-x 2 root root 4096 Nov 15 10:32 log
drwxr-xr-x 2 root root 4096 Nov 15 10:32 public
-rw-r--r-- 1 root root 249 Nov 15 10:32 Rakefile
-rw-r--r-- 1 root root 478 Nov 15 10:32 README.rdoc
-rw-r--r-- 1 root root 8 Nov 15 10:32 .rspec
drwxr-xr-x 3 root root 4096 Nov 15 10:32 spec
drwxr-xr-x 3 root root 4096 Nov 15 10:32 vendor
答案 0 :(得分:4)
首先必须创建tmp目录,然后为其提供必要的权限。这可以使用以下代码完成:
sudo mkdir tmp
sudo chmod 777 tmp
答案 1 :(得分:0)
因为每次运行rails服务器时,都会在server.pid
文件夹中创建名为tmp/pids
的新文件。在您运行服务器的情况下,它会尝试创建pid,但您没有权限在此文件夹下创建任何文件。您需要为tmp
目录提供写入权限。