gpt4 book ai didi

ruby-on-rails - 'rails server' 命令返回错误 : `mkdir' : Permission denied @ dir_s_mkdir

转载 作者:行者123 更新时间:2023-12-05 01:02:35 25 4
gpt4 key购买 nike

我正在尝试运行我下载的 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

最佳答案

首先必须创建 tmp 目录,然后给它必要的权限。这可以通过以下代码完成:

sudo mkdir tmp
sudo chmod 777 tmp

关于ruby-on-rails - 'rails server' 命令返回错误 : `mkdir' : Permission denied @ dir_s_mkdir,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33754137/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com