Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Abanoub Hanna
Abanoub Hanna

Posted on • Edited on • Originally published atabanoubhanna.com

How to upgrade npm in Laravel Sail ?

When I stop the vite live serversail npm run dev of Laravel byctrl + 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.5npm notice Changelog: https://github.com/npm/cli/releases/tag/v9.6.5npm notice Run npm install -g npm@9.6.5 to update!npm notice
Enter fullscreen modeExit fullscreen mode

Here is a screenshot of the npm upgrade notice.

Image description

Upgrade npm inside Laravel Sail Docker environment

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

What should I do?

I usesail root-shell to get the Docker environment root shell. Then I usenpm install -g npm@9.6.5. 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.

Image description

But this is not the correct way to upgrade npm inside a docker container (such as Laravel Sail). Thecorrect 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
Enter fullscreen modeExit fullscreen mode

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 onYouTube,Twitter (x),LinkedIn, andGitHub.

Top comments(4)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
dr41d45 profile image
dr41d45
  • Joined

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

CollapseExpand
 
abanoubha profile image
Abanoub Hanna
software developer. I love to code and blog! I hope to help people with my coding skills and my explains.
  • Location
    Egypt
  • Pronouns
    he/him
  • Work
    KartBusiness.com
  • Joined

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

CollapseExpand
 
dr41d45 profile image
dr41d45
  • Joined
• Edited on• 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 fromwww.

Thread Thread
 
abanoubha profile image
Abanoub Hanna
software developer. I love to code and blog! I hope to help people with my coding skills and my explains.
  • Location
    Egypt
  • Pronouns
    he/him
  • Work
    KartBusiness.com
  • Joined

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

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

software developer. I love to code and blog! I hope to help people with my coding skills and my explains.
  • Location
    Egypt
  • Pronouns
    he/him
  • Work
    KartBusiness.com
  • Joined

More fromAbanoub Hanna

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp