Running setup-ruby (GitHub Actions) on EC2 throws ENOENT: no such file or directory, mkdir

Viewed 489

Context

I am setting up CI on GitHub Actions, which was recently connected to an Amazon Linux 2 instance. I suspect the problems are to do with permissions when ruby-setup tries to make new folders on the instance, but the stack trace is vague. This happens in two distinct jobs that both require ruby.

Stacktrace

Run ruby/setup-ruby@v1
  with:
    ruby-version: default
    bundler: default
    bundler-cache: false
    working-directory: .
    cache-version: 0
  env:
    ImageOS: ubuntu20
    JAVA_HOME_8_x64: /home/ec2-user/actions-runner/_work/_tool/jdk/8.0.292/x64
    JAVA_HOME: /home/ec2-user/actions-runner/_work/_tool/jdk/8.0.292/x64
    JAVA_HOME_8_X64: /home/ec2-user/actions-runner/_work/_tool/jdk/8.0.292/x64
Using ruby-2.3.1 as input from file .ruby-version
Error: ENOENT: no such file or directory, mkdir

and

Run ruby/setup-ruby@v1
  with:
    ruby-version: default
    bundler: default
    bundler-cache: false
    working-directory: .
    cache-version: 0
  env:
    PGHOST: localhost
    PGUSER: postgres
    RAILS_ENV: test
    ImageOS: ubuntu20
Using ruby-2.3.1 as input from file .ruby-version
Error: ENOENT: no such file or directory, mkdir

Before setup-ruby, checkout runs successfully for both steps.

setup-ruby

https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby

Troubleshooting

I have tried:

  • Modifying permissions for the user (ec2-user)
  • Looking for alternative Actions, this appears to be the only one maintained

What do I need to do so that these steps can complete?

1 Answers

It's a confusing error, but what it actually says is that it tried to create a directory, but the parent directory does not exist. Make sure you have /opt/hostedtoolcache and it's writable by runner user. Easiest way to achieve this:

mkdir /opt/hostedtoolcache && chmod -R 777 /opt/hostedtoolcache
Related