Skip to content

Instantly share code, notes, and snippets.

@victorekpo
Forked from kelsS/gitbash-npm-windows.md
Created August 16, 2023 10:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save victorekpo/ba521a009b20502eb3e7ea42a4e12b06 to your computer and use it in GitHub Desktop.
Save victorekpo/ba521a009b20502eb3e7ea42a4e12b06 to your computer and use it in GitHub Desktop.
Better way to use Git Bash and Node/NPM on Windows.

Resource

  1. Download Git for Windows Portable (Comes with Git Bash included)
  2. Download Node with npm
  3. Create Applications folder in C: drive so that you have the proper permissions
  • C:\Applications
  1. Install Git for Windows inside of Applications directory
  • C:\Applications\Git
  1. Install Node inside of Applications directory
  • C:\Applications\nodejs

Folder structure

Applications
├─ Git
│  ├─ git_bash.exe
│  └─ etc
│     ├─ profile (edited)
│     └─ node_env.conf
└─ nodejs
   ├─ node
   └─ npm

Configure the Git Bash Shell

  • List the content of the Applications directory ls /c/Applications
  1. Type this export command into Git Bash export PATH=$PATH:/c/Applications/nodejs
  • To check that the path was exported type node --version and npm --version
  • The version numbers should display in the terminal
  • If they do not display, check that npm and node.exe are actually located inside of C:\Applications\nodejs

Persisiting Git Bash Terminal Configuration

  1. Create a custom config file in C:\Applications\Git\etc\node_env.conf
# Include nodejs PATH
PATH=$PATH:/c/Applications/nodejs
  1. Edit the Git Bash Profile
  • C:\Applications\Git\etc\profile
  • Add source "etc/node_env.conf" to the space right before the EXPORT PATH line
  • You should now be able to use npm and Node from Git Bash

Using New Git Bash Config with VS Code

  • To use this new Git Bash configuration with the VS Code integrated terminal you need to change the terminal path in the settings.json
  1. In VS Code open file
  2. Hover over preferences
  3. Click settings
  4. Add the following code to the settings.json file inside the curly braces
"terminal.integrated.shell.windows": "C:\\Applications\\Git\\bin\\bash.exe",
  1. Save the file and reload VS Code
  2. Check Node and NPM versions inside the integrated terminal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment