Skip to content

Error: EACCES: permission denied, mkdir '/opt/hostedtoolcache/node' #18

Description

@leogomide

Im facing the following error Error: EACCES: permission denied, mkdir '/opt/hostedtoolcache/node' when running the workflow below

name: Deploy to Desenv

on:
  workflow_dispatch:
    inputs:
      runner:
        description: "Choose runner"
        required: true
        default: "self-hosted"
        type: choice
        options:
          - self-hosted
          - ubuntu-latest

env:
  NODE_VERSION: '20.x'

jobs:
  deploy-database:
    name: Deploy Prisma Migrations
    runs-on: ${{ github.event.inputs.runner }}
    environment: DESENV

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: ${{ env.NODE_VERSION }}
          cache: 'npm'

      - name: Cache dependencies
        uses: actions/cache@v4
        with:
          path: ~/.npm
          key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-node-

      - name: Install dependencies
        run: npm ci

this error do not occour when i run it on ubuntu-latest

i have found a solution using gemini by creating the toolcache directory before running the setup node action, the fixed workflow is

name: Deploy to Desenv

on:
  workflow_dispatch:
    inputs:
      runner:
        description: "Choose runner"
        required: true
        default: "self-hosted"
        type: choice
        options:
          - self-hosted
          - ubuntu-latest

env:
  NODE_VERSION: '20.x'

jobs:
  deploy-database:
    name: Deploy Prisma Migrations
    runs-on: ${{ github.event.inputs.runner }}
    environment: DESENV

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Create Node.js toolcache directory
        run: sudo mkdir -p /opt/hostedtoolcache/node && sudo chown -R $(whoami):$(whoami) /opt/hostedtoolcache/node

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: ${{ env.NODE_VERSION }}
          cache: 'npm'

      - name: Cache dependencies
        uses: actions/cache@v4
        with:
          path: ~/.npm
          key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-node-

      - name: Install dependencies
        run: npm ci

gemini also suggested to make this changes, maybe doing this in the dockerfile fix the issue

The error EACCES: permission denied, mkdir '/opt/hostedtoolcache/node' on a self-hosted runner indicates that the user running the GitHub Actions runner process does not have the necessary permissions to create directories within /opt/hostedtoolcache/node. This directory is typically used by actions like setup-node to cache Node.js versions.
To resolve this issue, you need to grant the appropriate permissions to the user account that is running the self-hosted runner. Here are a few common solutions:
Change ownership and permissions of the /opt/hostedtoolcache directory:
Ensure that the user account running the self-hosted runner is the owner of the /opt/hostedtoolcache directory and has write permissions.
    sudo chown -R <runner_user>:<runner_group> /opt/hostedtoolcache
    sudo chmod -R 755 /opt/hostedtoolcache

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions