DEV Community

Abanoub Hanna
Abanoub Hanna

Posted on • Originally published at valueinbrief.com

How to upgrade npm in Laravel Sail ?

When I stop the vite live server sail npm run dev of Laravel 10 by ctrl + c, the CLI tells me to upgrade npm with this message.

npm notice 
npm notice New patch version of npm available! 9.6.4 -> 9.6.5
npm notice Changelog: https://github.com/npm/cli/releases/tag/v9.6.5
npm notice Run npm install -g npm@9.6.5 to update!
npm notice 
Enter fullscreen mode Exit fullscreen mode

Here is a screenshot of the npm upgrade notice.

Image description

Upgrade npm inside Laravel Sail Docker environment

You can not just run npm install -g npm@9.6.5 and upgrade. This is not your docker-contained npm! and if your wanna upgrade by sail npm install -g npm@9.6.5, you don’t have the permissions to upgrade npm like that.

What should I do?

I use sail root-shell to get the Docker environment root shell. Then I use npm install -g npm@9.6.5. And voila, it works.

Here is a screenshot of steps and commands I used.

Image description

I hope this helps. Share if you care.

Follow me to get notified of new posts I create. Follow me on Twitter @abanoubha. Follow me on LinkedIn. Join my Telegram channel @softwarepharaoh. Follow my Facebook page @softwarepharaoh.

Top comments (4)

Collapse
 
dr41d45 profile image
dr41d45

totally nonsense to do that. You have mess with permissions.

Collapse
 
abanoubha profile image
Abanoub Hanna

So, what is the ideal way to upgrade npm inside Sail?

Collapse
 
dr41d45 profile image
dr41d45 • Edited

you should need recreate docker container. If you look at Dockerfile, you will see required place.
...
&& apt-get install -y nodejs \
&& npm install -g npm \

...

PS in our company sail container is even isolated from www.

Thread Thread
 
abanoubha profile image
Abanoub Hanna

Thanks for your reply. I will try to upgrade it on the dockerfiles.