1

I have an azure app-services as node v14, however, the app-services pre-install NPM as version 6.14

Then I try to upgrade to the latest on SSH as:

sudo npm install -g npm@latest

but didn't work. Any ideas??? How we can update this? Or is not possible?

jcdsr
  • 1,123
  • 1
  • 17
  • 35

5 Answers5

1

I also spent hours trying to upgrade node from Kudu as well. Here's what worked for me.

From Azure Portal, enter the applicable App Service blade. Inside Settings -> Configuration there is an Application settings tab with a Name: WEBSITE_NODE_DEFAULT_VERSION. Value: Hidden value... (click on it -> Advanced edit)

I changed the version to 16.13.0

The app service restarted and with node 16.13.0.

kvmm
  • 11
  • 1
1

Just go to Azure portal, select the App Service -> Web App -> Application settings. Under Application settings, add the setting WEBSITE_NODE_DEFAULT_VERSION with required version number. ~14 worked for me.

Anna Gevel
  • 1,103
  • 1
  • 11
  • 20
-1

We have tested in our environment , by creating a webapp with runtime stack as NodeJS , operating system as windows. we are able to upgrade the Nodejs version in kudu by adding the application setting.

WEBSITE_NODE_DEFAULT_VERSION:<supportednodejsVersion Value>

you can get the supported NodeJS version value by routing to the below path of your web site

https://<yourwebappname>.scm.azurewebsites.net/api/diagnostics/runtime

Here is the reference output :

enter image description here

Here is the reference SO threads.

VenkateshDodda
  • 4,723
  • 1
  • 3
  • 12
  • our environment is on Linux and after we upgrade npm to the new version, the web app becomes unresponsive, plus didn't run any cli as npm. However, works after reverting back to the old version. Try install the new version and then restart and see what will happen – jcdsr Oct 19 '21 at 08:21
  • we have create a new nodejs app service on linux environment of app service plan P1V2 , we had ran the cmdlet "sudo npm install -g npm@latest" and it failed stating sudo is not found as shown in [figure](https://i.stack.imgur.com/MBcLX.png) – VenkateshDodda Oct 20 '21 at 12:58
  • We ran this cmdlet in the ssh terminal 'npm install -g npm@latest' this given us latest npm package that is available , it has requested to rum the below cmdlet 'npm install -g npm ' if you want to upgrade the npm version "npm install -g npm@latest" .post the cmdlet execution was completed we are able to see that npm got upgraded to [latest version of 8.1.0](https://i.stack.imgur.com/u4cI4.png) & webapp is working fine. As suggested we have restarted the web app & tried connecting back through ssh when we ran the below cmdlet "npm -v" it got reverted back to the older version. – VenkateshDodda Oct 20 '21 at 13:07
  • as well the npm version is reverted back if we change the node version under > configuration > general settings – jcdsr Oct 20 '21 at 16:26
-1

If it is not possible to install the updated version in your environment, a workaround would be to use npx to invoke the latest npm like this:

npx -p npm@latest npm

So, instead of running npm install or npm ci, you could run npx -p npm@latest npm install or npx -p npm@latest npm ci.

That workaround aside, I don't know much about Azure App Service specifically, but if you can run command -v npm, that should give you the path where npm is installed. From there, you may be able to tell what might be the problem. (One thing worth trying if you haven't yet is to run npm install -g npm@latest without sudo. Using sudo with npm is a bit of an anti-pattern and someone may have taken steps to thwart it.)

Trott
  • 66,479
  • 23
  • 173
  • 212
  • it doesn't work, the version is reverted after a restart – jcdsr Oct 28 '21 at 14:59
  • @jcdsr Using `npx -y -p npm@latest npm` will always run the latest `npm` (assuming you have a network connection so it can get the latest npm from the registry). There is nothing to persist after restart. – Trott Oct 28 '21 at 16:17
  • doesn't work, ===> npx -y -p npm@latest npm npx: installed 203 in 22.889s npm info it worked if it ends with ok npm info using npm@6.14.10 npm info using node@v14.15.1 Usage: npm ..... npm -h quick help on npm -l display full usage info npm help search for help on npm help npm involved overview Specify configs in the ini-formatted file: /root/.npmrc or on the command line via: npm --key value Config info can be viewed via: npm help config npm@6.14.10 /usr/local/lib/node_modules/npm – jcdsr Oct 28 '21 at 16:26
  • @jcdsr Interesting. I bet it will work if you remove the `-y`. I'll update my answer. – Trott Oct 28 '21 at 16:34
  • Nop, didn't work by removing -y – jcdsr Oct 28 '21 at 16:51
  • What you mean by "didn't work"? What's the output of `npx -p npm@latest npm --version`? – Trott Oct 28 '21 at 16:55
-1

For Windows, additional steps are required. To make things easy, you can use the npm-windows-upgrade package.

  1. Open Powershell as administrator
  2. Execute Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
  3. Execute npm install -g npm-windows-upgrade
  4. Execute npm-windows-upgrade
  5. Use the up/down arrows to select the correct NPM version.

After executing the above steps, you can see that now the correct version of NPM has been installed by executing npm -v.

Stijn
  • 219
  • 1
  • 3