24

I used Ruby on Rails on Red Hat server. When I trying to generate a controller file, I got this error:

[ec2-user@ip-172-31-22-128 testApp4]$ rails generate controller welcome
/home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/server.rb:22:in `initialize': Permission denied @ rb_sysopen - /tmp/spring/fea371aaf9d69cfa58bd12f69b3f1bf6.pid (Errno::EACCES)
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/server.rb:22:in `open'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/server.rb:22:in `open'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/server.rb:22:in `initialize'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/server.rb:14:in `new'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/server.rb:14:in `boot'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/run.rb:43:in `block in boot_server'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/run.rb:41:in `fork'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/run.rb:41:in `boot_server'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/run.rb:24:in `call'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/command.rb:7:in `call'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/rails.rb:23:in `call'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/command.rb:7:in `call'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client.rb:26:in `run'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/bin/spring:48:in `<top (required)>'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/binstub.rb:11:in `load'
from /home/ec2-user/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/binstub.rb:11:in `<top (required)>'
from /home/ec2-user/testApp4/bin/spring:16:in `require'
from /home/ec2-user/testApp4/bin/spring:16:in `<top (required)>'
from bin/rails:3:in `load'
from bin/rails:3:in `<main>'

7 Answers 7

36

I solved that problem by running

sudo chmod -R 1777 /tmp

hope this helps other people like me who would prefer not having to deactivate the spring gem

3
  • 1
    If you are on a shared system, 777 will give all other users read and write access to those files... not a good idea.
    – Blaskovicz
    Mar 5, 2017 at 16:12
  • 1
    Was not helpful for m
    – em_
    Jun 28, 2017 at 14:41
  • For me it was showing error: Permission denied @ dir_s_mkdir - /run/user/1000 Fixed it after running > sudo chmod -R 1777 /run/user/
    – Omer Aslam
    Sep 18, 2019 at 18:11
12

It needs ownership to write the re-write the pid for each server start.

I had to run it with my full local path & sudo

$ sudo chmod -R 777 /Users/MyName/Desktop/projects/my_project/tmp/

6

I took a look at the library that's trying to write the pid file, lib/spring/env.rb.

The function in question tries to create a temporary directory at the same location each time unless the XDG_RUNTIME_DIR is set:

path = Pathname.new(File.join(ENV['XDG_RUNTIME_DIR'] || Dir.tmpdir, "spring"))

Setting said variable to a unique directory does the trick for me:

export XDG_RUNTIME_DIR=/tmp/`whoami`
2

Missing permission for tmp folder to writable . run chmod 777 tmp/

11
  • 1
    I ran chmod 777 tmp/, and the problem still exists. May 23, 2014 at 6:56
  • 1
    (sudo) chmod 1777 /tmp, not 777, nor tmp/.
    – DMKE
    May 23, 2014 at 7:23
  • 1
    Do you have the same or similar problems, when you remove the spring gem from your Gemfile, run the bundle command and try generating a controller again?
    – DMKE
    May 23, 2014 at 8:14
  • 1
    @DMKE you genius!! remove the spring and run it again. Now everything works normal! Thank you so much! But What exactly spring do? is it a must for rails? how can I fixed this problem? May 23, 2014 at 8:54
  • 1
    Well, it's not the solution for the problem, just a mere workaround.
    – DMKE
    May 23, 2014 at 9:19
2

I had this same issue when working on a Rails 6 application in Ubuntu 20.04.

Each time I run the command rails assets:clobber to remove the old assets in public/assets completely, I get the error:

errno::enotempty: directory not empty @ dir_s_rmdir

errno::eacces: permission denied @ apply2files

And the logs pointed the path to the file causing it, which in my a case was the public/packs/manifest.json file.

I tried deleting it or changing permission but nothing worked. I also tried deleting the tmp directory in the project, but it did not work.

Here's how I fixed it:

I listed all the files and directories in that directory using the ls -lh command, which gave me this output:

-rw-rw-r-- 1 promisechukwuenyem promisechukwuenyem 1.7K Oct  6 20:29 404.html
-rw-rw-r-- 1 promisechukwuenyem promisechukwuenyem 1.7K Oct  6 20:29 422.html
-rw-rw-r-- 1 promisechukwuenyem promisechukwuenyem 1.6K Oct  6 20:29 500.html
-rw-rw-r-- 1 promisechukwuenyem promisechukwuenyem    0 Oct  6 20:29 apple-touch-icon.png
-rw-rw-r-- 1 promisechukwuenyem promisechukwuenyem    0 Oct  6 20:29 apple-touch-icon-precomposed.png
drwxr-xr-x 3 promisechukwuenyem promisechukwuenyem 4.0K Oct 13 09:20 armstrong_tools
-rw-rw-r-- 1 promisechukwuenyem promisechukwuenyem    0 Oct  6 20:29 favicon.ico
drwxr-xr-x 3 root               root               4.0K Oct  8 13:06 packs
-rw-rw-r-- 1 promisechukwuenyem promisechukwuenyem   99 Oct  6 20:29 robots.txt

I realized that the permissions for the files and directories were fine, however, the packs directory had root ownership which was seperate from persmission of other files and directories:

drwxr-xr-x 3 root               root               4.0K Oct  8 13:06 packs

I simply ran the command below to change the ownership from root to promisechukwuenyem:

sudo chown -R promisechukwuenyem:promisechukwuenyem packs/

Now when I ran the command rails assets:clobber to remove the old assets in public/assets completely, it worked just fine.

That's all.

I hope this helps

-1

Or,

export XDG_RUNTIME_DIR=/run/user/${id -u}

to change this system variable. id -u returns your UID(user id), which is the dir name where you have access to write/read under /run/user/.

-1

I am getting this type of error(permission denied @ apply2files) when using rails server.

sudo rails server solve my problem.

1
  • 1
    Starting rails with sudo is not recommendable. It does work, but it also gives the rails application superuser access, which is a security issue. Oct 29, 2022 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.