13

I tried Install-Package nodejs, which seems to have done something:

PS C:\WINDOWS\system32> Install-Package nodejs

The package(s) come(s) from a package source that is not marked as trusted.
Are you sure you want to install software from 'chocolatey'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): y

Name                           Version          Source           Summary
----                           -------          ------           -------
nodejs.install                 11.10.0          chocolatey       Node JS - Evented I/O for v8 JavaScript.
nodejs                         11.10.0          chocolatey       Node JS - Evented I/O for v8 JavaScript.

Then when I try to run the node command, it fails:

PS C:\WINDOWS\system32> node
node : The term 'node' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ node
+ ~~~~
    + CategoryInfo          : ObjectNotFound: (node:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

How do I do it properly with PackageManager, so that the command is then available?

Not sure if this other question is related: Chocolaty packages not installing via OneGet/PackageManagement in Windows 10?

As that other question suggests, I tried setting Set-ExecutionPolicy Unrestricted, the uninstalling and reinstalling nodejs, but the result is the same.

I do see that after install the following files exist:

C:\Chocolatey\lib\nodejs.11.10.0\nodejs.11.10.0.nupkg
C:\Chocolatey\lib\nodejs.install.11.10.0.nupkg\nodejs.install.11.10.0.nupkg
C:\Chocolatey\lib\nodejs.install.11.10.0.nupkg\nodejs.install.11.10.0.nupkg
C:\Chocolatey\lib\nodejs.install.11.10.0.nupkg\nodejs.install.11.10.0.nupkg\legal\LICENSE.txt
C:\Chocolatey\lib\nodejs.install.11.10.0.nupkg\nodejs.install.11.10.0.nupkg\legal\VERIFICATION.txt
C:\Chocolatey\lib\nodejs.install.11.10.0.nupkg\nodejs.install.11.10.0.nupkg\tools\chocolateyInstall.ps1
C:\Chocolatey\lib\nodejs.install.11.10.0.nupkg\nodejs.install.11.10.0.nupkg\tools\node-v11.10.0-x64.msi
C:\Chocolatey\lib\nodejs.install.11.10.0.nupkg\nodejs.install.11.10.0.nupkg\tools\node-v11.10.0-x86.msi

which makes me think that maybe it expects me to run the installer manually after?

My goal is to simply install anything I need on a new Windows machine from a script, without having to download/install them all manually with GUIs.

trusktr
  • 44,284
  • 53
  • 191
  • 263
  • Is there any reason you are not downloading the official executable directly? Also, did you try the "nodejs" alias instead of "node"? – Azami Feb 18 '19 at 02:04
  • 2
    @MadWard I want to install everything I need on a new Windows system using a script. I'm just tired of manually downloading files and then manually running GUIs to install everything. It is slooooow. So now that I'm setting up a new Windows machine, I want to write a script as I go so that the next time it'll be a breeze (like I already have for Linux and macOS). I thought I could do it with the new builtin `PackageManager`, but if that proves to be too difficult, then I'll just go with choco if that's easier, but I wanted to try a builtin solution first. – trusktr Feb 18 '19 at 02:11
  • Why not just [wget](https://4sysops.com/archives/use-powershell-to-download-a-file-with-http-https-and-ftp/) the .msi from official, say https://nodejs.org/dist/v10.15.1/node-v10.15.1-x64.msi , and use [msiexec](https://powershellexplained.com/2016-10-21-powershell-installing-msi-files/) to install? – Eric Wong Feb 18 '19 at 15:52
  • 1
    @EricWong Well, I though `Install-Package nodejs` was supposed to be easy, that's why. I ended up switching to `choco` and installing stuff works. I don't want to write different setup instructions for each package, if I can have one command to install every package. – trusktr Feb 20 '19 at 02:44

4 Answers4

2

I was able to reproduce this, but also was able to resolve it. The issue is that the node executable isn't on the PATH after installing with Install-Package. However, this does make some sense as the current PowerShell process won't pick up outside changes to environment variables until it is relaunched.

Chocolatey's refreshenv command works sometimes but not always, and after installing nodejs with Install-Package, refreshenv did not work to refresh the PATH variable. What did work was launching a new PowerShell session and running the node command, which ran the executable successfully:

> node

Welcome to Node.js v16.7.0.
Type ".help" for more information.
> 

choco.exe can sometimes mask this but usually Chocolatey won't generate shims for executables placed by EXE or MSI installers (unless the package maintainer forcibly creates them).

Tip: In case you are in a situation where you need to call the binary from the same process that installed the package (e.g. during a chef-client run where refreshenv isn't an option), use the fully-qualified path to the executable to invoke the newly-installed software.


Additionally, don't use the Chocolatey OneGet provider in real automation; it's not yet stable and looks like it hasn't seen any development activity in five years at this time of writing. From the README.md:

NOTE: Seeking maintainers to help finish this Provider. Please inquire on the issues list or on Gitter (see the chat room below). Thanks!

There is an alternative listed in the same README:

NOTE: For now, you may be more interested in using the ChocolateyGet provider as a stop gap solution until this provider is ready. See https://github.com/jianyunt/ChocolateyGet for details

I tried this and it seems to work, but I would still recommend using the official choco.exe binary. It's easy to install and you'll get the best support when using it. It's also telling that configuration management solutions (such as Chef's chocolatey_package resource) continue to make use of the binaries and will generally list installing the client as a prerequisite, even though technically the PackageManagement module could be used as a native solution instead.

codewario
  • 19,553
  • 20
  • 90
  • 159
1

Try using this command on your powershell:

npm install -g npm

For further info refer to this URL:
https://www.webdevtutor.net/error-solutions/npm-the-term-npm-is-not-recognized-as-the-name-of-a-cmdlet-function-script-file-or-operable-program

Tyler2P
  • 2,324
  • 26
  • 22
  • 31
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/34642985) – sanitizedUser Jul 10 '23 at 00:29
  • This worked like a charm, thank you :) – ragnarswanson Aug 10 '23 at 17:49
0

It worked for me:

winget install nodejs
Tyler2P
  • 2,324
  • 26
  • 22
  • 31
  • A good answer will always include an explanation why this would solve the issue, so that the OP and any future readers can learn from it. – Tyler2P Oct 16 '22 at 10:49
0

I had the same issue. Try running : node.exe

CadetD
  • 1
  • 1