Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gemfile.lock write error, permissions?

I created a Rails model "model" a while ago and now I'm trying to run the server. After a bundle install I get:

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

Tried rails s to see what happens and:

/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 `'

Can I set the permissions for the Gemfile.lock so I can bundle and run server?

$ 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

Model files created incorrectly?

like image 872
jerseybyte Avatar asked Jul 08 '13 04:07

jerseybyte


People also ask

Can I manually edit Gemfile lock?

Gemfile. lock is automatically generated when you run bundle install or bundle update . It should never be edited manually.

What is difference between Gemfile and Gemfile lock?

The Gemfile is where you specify which gems you want to use, and lets you specify which versions. The Gemfile. lock file is where Bundler records the exact versions that were installed. This way, when the same library/project is loaded on another machine, running bundle install will look at the Gemfile.

Should you commit Gemfile lock?

A: Yes, you should commit it. The presence of a `Gemfile. lock` in a gem's repository ensures that a fresh checkout of the repository uses the exact same set of dependencies every time.

Is Gemfile lock auto generated?

A Gemfile. lock is auto-generated & it says exactly what versions of every gem were installed. Bundler will install these versions so when you deploy this application to production, or share your project with other developers, everyone will be working with an identical set of gems.


2 Answers

Your app root directory (whose permissions govern file creation) and files are all owned by root instead of your user (possibly because you did sudo rails new—don’t use sudo for that). You can change the permissions by doing:

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

Where “myappfolder” is your Rails app’s root directory.

By the way, a good tip with regard to sudo is to always try the command without it first, then, if there’s a permissions error when it runs, you may need sudo. Don’t default to using sudo.

like image 79
Andrew Marshall Avatar answered Sep 29 '22 19:09

Andrew Marshall


Sometimes the above answer:

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

will give you the error:

chown: ifeegoo: illegal group name 

You can also try this kind of command:

sudo chown -R ifeegoo: /Users/ifeegoo/workspace/rails/Test 
like image 29
ifeegoo Avatar answered Sep 29 '22 18:09

ifeegoo