Skip to content

Instantly share code, notes, and snippets.

@kelsS
Last active October 7, 2024 00:45
Show Gist options
  • Save kelsS/0ecdc9209fef8fa3d8842cab399eb976 to your computer and use it in GitHub Desktop.
Save kelsS/0ecdc9209fef8fa3d8842cab399eb976 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