ruby - Gemfile.lock 写入错误,权限?

不久前我创建了一个 Rails 模型“模型”,现在我正在尝试运行服务器。在 bundle install 之后,我得到:

There was an error while trying to write to Gemfile.lock. It is likely that you need to allow write permissions for the file at path: /home/thiago/model/Gemfile.lock

试过 rails s 看看会发生什么,然后:

/home/thiago/.rvm/gems/ruby-1.9.3-p429/gems/bundler-1.3.5/lib/bundler/definition.rb:235:in `rescue in lock': There was an error while trying to write to Gemfile.lock. It is likely that  (Bundler::InstallError)
you need to allow write permissions for the file at path: 
/home/thiago/model/Gemfile.lock
  from /home/thiago/.rvm/gems/ruby-1.9.3-p429/gems/bundler-1.3.5/lib/bundler/definition.rb:220:in `lock'
  from /home/thiago/.rvm/gems/ruby-1.9.3-p429/gems/bundler-1.3.5/lib/bundler/environment.rb:34:in `lock'
  from /home/thiago/.rvm/gems/ruby-1.9.3-p429/gems/bundler-1.3.5/lib/bundler/runtime.rb:43:in `setup'
  from /home/thiago/.rvm/gems/ruby-1.9.3-p429/gems/bundler-1.3.5/lib/bundler.rb:120:in `setup'
  from /home/thiago/.rvm/gems/ruby-1.9.3-p429@global/gems/rubygems-bundler-1.1.1/lib/rubygems-bundler/noexec.rb:79:in `setup'
  from /home/thiago/.rvm/gems/ruby-1.9.3-p429@global/gems/rubygems-bundler-1.1.1/lib/rubygems-bundler/noexec.rb:91:in `'
  from /home/thiago/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:110:in `require'
  from /home/thiago/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:110:in `rescue in require'
  from /home/thiago/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:35:in `require'
  from /home/thiago/.rvm/gems/ruby-1.9.3-p429/bin/ruby_noexec_wrapper:9:in `'

我可以设置 Gemfile.lock 的权限,以便我可以 bundle 和运行服务器吗?

$ ls -a -l
total 80
drwxr-xr-x. 13 root   root   4096 May 19 14:08 .
drwx------. 41 thiago thiago 4096 Jul  7 23:51 ..
drwxr-xr-x.  8 root   root   4096 May 19 14:08 app
drwxr-xr-x.  5 root   root   4096 May 19 14:08 config
-rw-r--r--.  1 root   root    155 May 19 14:08 config.ru
drwxr-xr-x.  2 root   root   4096 May 19 14:08 db
drwxr-xr-x.  2 root   root   4096 May 19 14:08 doc
-rw-r--r--.  1 root   root    765 May 19 14:08 Gemfile
-rw-r--r--.  1 root   root    430 May 19 14:08 .gitignore
drwxr-xr-x.  4 root   root   4096 May 19 14:08 lib
drwxr-xr-x.  2 root   root   4096 May 19 14:08 log
drwxr-xr-x.  2 root   root   4096 May 19 14:08 public
-rw-r--r--.  1 root   root    270 May 19 14:08 Rakefile
-rw-r--r--.  1 root   root   9208 May 19 14:08 README.rdoc
drwxr-xr-x.  2 root   root   4096 May 19 14:08 script
drwxr-xr-x.  7 root   root   4096 May 19 14:08 test
drwxr-xr-x.  3 root   root   4096 May 19 14:08 tmp
drwxr-xr-x.  4 root   root   4096 May 19 14:08 vendor

模型文件创建不正确?

最佳答案

您的应用根目录(其权限控制文件创建)和文件都归 root 而不是您的用户所有(可能是因为您使用了 sudo rails new——不要使用 sudo 为此)。您可以通过以下方式更改权限:

sudo chown -R $(whoami):$(whoami) myappfolder

其中“myappfolder”是 Rails 应用的根目录。

顺便说一句,关于 sudo 的一个好技巧是总是先尝试没有它的命令,然后,如果在运行时出现权限错误,您可能需要 sudo。不要默认使用 sudo

https://stackoverflow.com/questions/17519090/

相关文章:

linux - PostgreSQL -bash : psql: command not found

linux - 寻找 Docker 容器进程? (从主持人的角度来看)

linux - 仅当当前行中存在字符串时才替换

linux - 如何更改某些文件模式/扩展名的权限?

linux - 如果目标文件夹不存在,scp 会创建它吗

linux - 如何将文件从远程服务器复制到本地计算机?

linux - bash 中的线程?

linux - 如何在列中格式化控制台输出

linux - 使用 grep 和 sed 递归查找和替换所有文件中的字符串

linux - 如何使用 AWK 合并两个文件?