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 [email protected] to update!
npm notice
Here is a screenshot of the npm upgrade notice.
pgrade npm inside Laravel Sail Docker environment ๐
You can not just run npm install -g [email protected]
and upgrade. This is not your docker-contained npm! and if your wanna upgrade by sail npm install -g [email protected]
, you don’t have the permissions to upgrade npm like that.
What should I do?
I can use sail root-shell
to get the Docker environment root shell. Then I use npm install -g [email protected]
. And voila, it works. But..
Here is a screenshot of steps and commands I used. Yes, it works as you can see on the screenshot below.
But this is not the correct way to upgrade npm inside a docker container (such as Laravel Sail). The correct method to upgrade is to rebuild the docker container.
The correct way to upgrade npm inside Laravel Sail ๐
The correct way to upgrade npm inside Laravel Sail is to modify the dockerfile of the Sail. Use this command to re-build the docker container of the Laravel Sail.
bash vendor/bin/sail build --no-cache
Then check the npm version inside the container to make sure it is uptodate.
I hope you enjoyed reading this post as much as I enjoyed writing it. If you know a person who can benefit from this information, send them a link of this post. If you want to get notified about new posts, follow me on YouTube , Twitter (x) , LinkedIn , and GitHub .