How to update npm in Laravel Sail
Asked Answered
T

3

7

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 [email protected] to update!

Therefore, I tried running sail npm install -g [email protected] 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.

Tonetic answered 26/6, 2021 at 16:5 Comment(0)
T
5

Thanks to @online Thomas (https://mcmap.net/q/1402798/-how-to-update-npm-in-laravel-sail), 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 [email protected] 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 [email protected] command outside of the docker's server.

Tonetic answered 8/9, 2021 at 19:18 Comment(2)
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 bashAwn
I also just discovered sail shell, which proxies to docker compose exec laravel.test bashAwn
A
13

Current working method:

sail root-shell
npm install -g npm@latest
Awn answered 14/4, 2022 at 10:3 Comment(4)
This is the cleanest solution.Alignment
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.Shults
For me npm install -g npm@latest worked instead of the update command you provided.Greaser
@Greaser - I've updated my answer with installAwn
T
5

Thanks to @online Thomas (https://mcmap.net/q/1402798/-how-to-update-npm-in-laravel-sail), 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 [email protected] 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 [email protected] command outside of the docker's server.

Tonetic answered 8/9, 2021 at 19:18 Comment(2)
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 bashAwn
I also just discovered sail shell, which proxies to docker compose exec laravel.test bashAwn
S
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.

Swage answered 29/6, 2021 at 6:59 Comment(1)
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.Tonetic

© 2022 - 2025 — McMap. All rights reserved.