Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

running into a problem installing node.js via powershell using fnm

Tags:

node.js

followed steps in the node.js server on how to install node.js, when giving the following command; node -v or nvm -v I get the following error message : 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 -v
  •   + CategoryInfo          : Ob
    jectNotFound: (node:String)
    [], CommandNotFoundException
      + FullyQualifiedErrorId : Co
    mmandNotFoundException
    
    

to get the version of node.js installed

like image 589
Almasi Avatar asked May 05 '26 21:05

Almasi


2 Answers

I'm going to assume a few things here:

I had a similar issue to this (using Windows 11).

The main issue lies in that PowerShell profiles are not created automatically upon installation (for some reason). The profile path needs to exist for the fnm script (containing fnm environment variables) to run--as mentioned in the fnm GitHub page

Steps:

Here is how to set up the PowerShell profile:

  1. First, check that your profile does not exist. in PowerShell, run: notepad $profile.

    If Notepad cannot find the path, continue below, otherwise, jump to step 3.

  2. Open PowerShell using admin access and paste the code:

     ps:> if (!(Test-Path -Path $PROFILE)) {
               New-Item -ItemType File -Path $PROFILE -Force
          }
    

    This basically create the profile path. (script from Microsoft).

    Restart PowerShell.

  3. Now we're going to make sure PowerShell is able to run scripts. Open it and run:

    ps:> Get-ExecutionPolicy
    
    # If it says Restricted, then it won't run node, or it's associated env variables.
    
  4. To change it, open PowerShell in admin access, and use this code to change the restriction for PowerShell execution policies:

ps:> Set-ExecutionPolicy -ExecutionPolicy Unrestricted

# Accept the change and restart PowerShell again.

This is my preferred option, since I have not experimented with the other options--found in the link in this bullet point.

  1. Now, you should be able to open the Profile path by running:
ps:> notepad $PROFILE

# append the script from the `fnm` documentation into the file
ps:> fnm env --use-on-cd | Out-String | Invoke-Expression
  1. Now you should be able to just type node --version and it should work with no issue.
like image 134
Mahmood Al Hosni Avatar answered May 09 '26 04:05

Mahmood Al Hosni


Copy the command:

fnm env --use-on-cd | Out-String | Invoke-Expression

Into $profile to save the settings.

like image 41
Joilson Silva Avatar answered May 09 '26 02:05

Joilson Silva