2

I have the following GitHub action:

name: Rubocop
on: push

jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - name: Install Rubocop
        run: gem install rubocop
      - name: Rubocop
        run: rubocop

When this action runs, I get the following error:

ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /var/lib/gems/2.5.0 directory.

How can I fix this?

Jason Swett
  • 43,526
  • 67
  • 220
  • 351

2 Answers2

7

Use the following as per the official GitHub Actions docs:

name: Linting

on: [push]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: ruby/setup-ruby@v1
      with:
        ruby-version: 2.6
    - run: bundle install
    - name: Rubocop
      run: rubocop

or if you don't have a gemfile:

name: Linting

on: [push]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: ruby/setup-ruby@v1
      with:
        ruby-version: 2.6
    - run: gem install rubocop
    - name: Rubocop
      run: rubocop

sudo gem install rubocop is another option as described in You don't have write permissions for the /var/lib/gems/2.3.0 directory

riQQ
  • 9,878
  • 7
  • 49
  • 66
0

Consider using docker. If your repo is to be containerized and your Action is a test it would be better to run the test in the same docker image environment rather than some GitHub's Ubuntu:

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - run: docker run -v $(pwd):/checkout ruby:alpine sh -c "cd checkout && gem install bundler && bundle install && bundle exec ruby test.rb"
Nakilon
  • 34,866
  • 14
  • 107
  • 142