5

I am currently using Laravel 8.48.2 with the Sail package. I set Sail up and running its image through Docker Desktop while using WSL 2 with a Ubuntu distro on Windows. All seems to be working fine.

After I ran sail npm install, the packages were installed successfully, but I received the following message:

npm notice New minor version of npm available! 7.18.1 -> 7.19.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v7.19.0
npm notice Run npm install -g npm@7.19.0 to update!

Therefore, I tried running sail npm install -g npm@7.19.0 which gave me the following message:

npm ERR! code EACCES
npm ERR! syscall rename
npm ERR! path /usr/lib/node_modules/npm
npm ERR! dest /usr/lib/node_modules/.npm-qUIFSsiV
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, rename '/usr/lib/node_modules/npm' -> '/usr/lib/node_modules/.npm-qUIFSsiV'
npm ERR!  [Error: EACCES: permission denied, rename '/usr/lib/node_modules/npm' -> '/usr/lib/node_modules/.npm-qUIFSsiV'] {
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'rename',
npm ERR!   path: '/usr/lib/node_modules/npm',
npm ERR!   dest: '/usr/lib/node_modules/.npm-qUIFSsiV'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/sail/.npm/_logs/2021-06-26T15_27_02_291Z-debug.log

How can I update the NPM version on Sail?

Thank you in advance.

gabys
  • 101
  • 1
  • 2
  • 11

3 Answers3

9

Current working method:

sail root-shell
npm install -g npm@latest
Sonny
  • 8,204
  • 7
  • 63
  • 134
  • 1
    This is the cleanest solution. – Robin van Baalen Aug 08 '22 at 11:52
  • I tried this solution and am now receiving this error when using `sail npm install`: OCI runtime exec failed: exec failed: unable to start container process: exec: "npm": executable file not found in $PATH: unknown Will be digging into it, but just wanted to bring this up in case others encountered it as well. – Thomas Aug 09 '22 at 15:06
  • 1
    For me `npm install -g npm@latest` worked instead of the update command you provided. – DrGregoryHouse Feb 15 '23 at 09:20
  • 1
    @DrGregoryHouse - I've updated my answer with `install` – Sonny Feb 20 '23 at 18:27
4

Thanks to @online Thomas (https://stackoverflow.com/a/68173952/14508436), in order to resolve my issue, I followed these steps:

  1. Within my Laravel project's directory, I ran this command... docker-compose exec laravel.test bash, which points you to the docker's server (or something like that), directly on your project's directory.
  2. I ran this command... npm install -g npm@7.19.0 which updated npm to a newer version without any issues.

I tried the chown and chmod commands as suggested by @online Thomas, but in vain. I still couldn't use the sail npm install -g npm@7.19.0 command outside of the docker's server.

gabys
  • 101
  • 1
  • 2
  • 11
  • 1
    Given that this is an answer for Laravel Sail, it's nice to note that `sail` will proxy to `docker compose`. - `sail exec laravel.test bash` – Sonny Apr 01 '22 at 14:34
  • I also just discovered `sail shell`, which proxies to `docker compose exec laravel.test bash` – Sonny Apr 08 '22 at 19:18
3

Looking at your log it seems the user you run as has insufficient permission on the folder /usr/lib/node_modules/. So what you might try is to log in to the container with docker-compose exec laravel.test bash and use chown -R user:group /usr/lib/node_modules/ with the current user and group (found by whoami). Or chmod the folder to have more looser permission overall on this folder.

online Thomas
  • 8,864
  • 6
  • 44
  • 85
  • Thank you for your guidance. The instructions that you gave me were very helpful, but the `chown` and `chmod` commands were not needed. I will post a more detailed explanation of what I did. – gabys Sep 08 '21 at 17:26