In this little article, we show how to install NPM on Windows using Chocolatey, which is a Linux-like packet manager like apt-get, yum & Co.

choco install -y nodejs-lts --force

Step 0: Decision: why not using VS Code or WebStorm in your Browser?

The quickest way of starting developing with the latest stable NPM is this: just develop a browser and choose between VS Code, WebStorm or IntelliJ:

More information…

… you still would like to install NPM on your Windows system? Okay, then let us install NPM on Windows using chocolatey:

Step 1: Install Chocolatey on Windows

We are following the installation instructions on https://chocolatey.org/install:

Step 1.1: Start Powershell as Admin

Start Windows Powershell ISE as Administrator
Starting Powershell on Windows 10
Starting Powershell on Windows 11
Starting Powershell on Windows 11

Windows Search on the lower left: PowerShell –> right-click ‚Window Powershell ISE ‚  -> run as Administrator

Step 1.2: Install

Get-ExecutionPolicy

# output: Restricted

If the output is Restricted, then:

Set-ExecutionPolicy AllSigned

You will be prompted, whether you really, really want to do it. Then say Yes, all.

Then we install Chocolatey:

Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

The output looks similar to:

# Output:
orcing web requests to allow TLS v1.2 (Required for requests to Chocolatey.org)
Getting latest version of the Chocolatey package for download.
Not using proxy.
Getting Chocolatey from https://community.chocolatey.org/api/v2/package/chocolatey/1.2.0.
Downloading https://community.chocolatey.org/api/v2/package/chocolatey/1.2.0 to C:\Users\olive\AppData\Local\Tem
p\chocolatey\chocoInstall\chocolatey.zip
Not using proxy.
Extracting C:\Users\olive\AppData\Local\Temp\chocolatey\chocoInstall\chocolatey.zip to C:\Users\olive\AppData\Lo
cal\Temp\chocolatey\chocoInstall
Installing Chocolatey on the local machine
Creating ChocolateyInstall as an environment variable (targeting 'Machine') 
  Setting ChocolateyInstall to 'C:\ProgramData\chocolatey'
WARNING: It's very likely you will need to close and reopen your shell 
  before you can use choco.
Restricting write permissions to Administrators
We are setting up the Chocolatey package repository.
The packages themselves go to 'C:\ProgramData\chocolatey\lib'
  (i.e. C:\ProgramData\chocolatey\lib\yourPackageName).
A shim file for the command line goes to 'C:\ProgramData\chocolatey\bin'
  and points to an executable in 'C:\ProgramData\chocolatey\lib\yourPackageName'.

Creating Chocolatey folders if they do not already exist.

WARNING: You can safely ignore errors related to missing log files when 
  upgrading from a version of Chocolatey less than 0.9.9. 
  'Batch file could not be found' is also safe to ignore. 
  'The system cannot find the file specified' - also safe.
chocolatey.nupkg file not installed in lib.
 Attempting to locate it from bootstrapper.
PATH environment variable does not have C:\ProgramData\chocolatey\bin in it. Adding...
WARNUNG: Not setting tab completion: Profile file does not exist at 'C:\Users\olive\OneDrive\Dokumente\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1'.
Chocolatey (choco.exe) is now ready.
You can call choco from anywhere, command line or powershell by typing choco.
Run choco /? for a list of functions.
You may need to shut down and restart powershell and/or consoles
 first prior to using choco.
Ensuring Chocolatey commands are on the path
Ensuring chocolatey.nupkg is in the lib folder

Step 2: Uninstall NodeJS, if installed

Windows Uninstall NodeJS
Windows 10
Windows 11

 

Search -> programs -> search for NodeJS -> right-click (if found) –> uninstall

Step 3: Install NodeJS

In the Admin Windows Powershell, perform the command (the --force option is needed only if the installation was attempted unsuccessfully before already).

choco install -y --force nodejs-lts 
# use nodejs instead of nodejs-lts for the latest unstable version instead, if you want to take the risk

It seems that choco install is installing the latest (unstable) NodeJs version. Please check on https://nodejs.org/en/download/ to find the latest stable LTS version. To install a specific version, use following command instead:

choco install -y --force nodejs@v12.13.0

Step 4: Check NodeJS Version

Open a GIT Bash or an MSDOS window (search „Git Bash“ or CMD“):

node -v
# output: v18.12.1

Step 5: Check NPM Version

The chocolatey installation of NodeJS also installs and activated NPM by default. We can check the version of NPM as follows:

# install npm
npm i -g npm 

# check version:
npm -v
# output:
8.19.3

Step 6 (optional): Install Angular CLI

npm i -g @angular/cli@8.3.19
# or for the latest version:
# npm i -g @angular/cli

# output:
C:\Users\olive\AppData\Roaming\npm\ng -> C:\Users\olive\AppData\Roaming\npm\node_modules\@angular\cli\bin\ng

> @angular/cli@8.3.19 postinstall C:\Users\olive\AppData\Roaming\npm\node_modules\@angular\cli
> node ./bin/postinstall/script.js

+ @angular/cli@8.3.19
added 102 packages from 108 contributors and updated 7 packages in 25.591s

Done

2 comments

Comments

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.