Skip to content

Instantly share code, notes, and snippets.

@shepherd44
Created September 9, 2021 15:45
Show Gist options
  • Save shepherd44/5b63769dffc1a29403b12dc234c7fd40 to your computer and use it in GitHub Desktop.
Save shepherd44/5b63769dffc1a29403b12dc234c7fd40 to your computer and use it in GitHub Desktop.
npm update script(with git bash on windows)
#!/bin/bash
npm_version=$(npm --version)
npm_path=$(which npm)
npm_dirname=$(dirname $npm_path)
echo current npm version: $npm_version
echo current npm dirpath: $npm_dirname
cd $npm_dirname
test -e npm && mv npm npm-$npm_version
test -e npm.ps1 && mv npm.ps1 npm-$npm_version.ps1
test -e npm.cmd && mv npm.cmd npm-$npm_version.cmd
test -e npx && mv npx npx-$npm_version
test -e npx.ps1 && mv npx.ps1 npx-$npm_version.ps1
test -e npx.cmd && mv npx.cmd npx-$npm_version.cmd
cd node_modules
mv npm npm-$npm_version
cd npm-$npm_version/bin
node npm-cli.js install -g npm@latest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment