My OS is win7, and I using MSYS2(version:MSYS_NT-6.1), Please give advice how to install nodejs and npm on this terminal, Thanks!
5 Answers
I found a solution for resolving the problem,
64bit env.
pacman -S mingw-w64-x86_64-nodejs
32bit env.
pacman -S mingw-w64-i686-nodejs
after installed, Open terminal
$ node -v
v6.11.0
-
3In addition,
npm
is distributed with Node.js which means that when you download Node.js, you automatically get npm installed. Check with$ npm -v
Commented May 24, 2018 at 13:35 -
3For those wondering why node.exe is not in the msys2 path, you need to use the appropriate mingw console. (32/64-bit) Commented Dec 18, 2018 at 17:44
-
3nodejs package is not available in msys packages (packages.msys2.org/search?t=pkg&q=nodejs)– Chris PCommented Nov 19, 2021 at 15:29
As of 2020, the package mingw-w64-x86_64-nodejs
is not available any more. The simplest way to have Node.js, npm and git installed on a Windows machine is using the official Windows installers:
- Git: https://git-scm.com/download/win
- Node.js (npm is shipped with it): https://nodejs.org/en/download/
After installation, open a command prompt (click on start, and then type cmd
and [ENTER]
) and verify that all three tools are there:
git --version
node --version
npm --version
Later on, to update Node.js, simply reinstall it from the same source.
-
If you use another terminal such as Windows Terminal, you have to add
-full-path
option when startingmsys2_shell.cmd
. The-full-path
option was not suggested for some reason in the official documentation at msys2.org/docs/terminals Commented May 31, 2021 at 6:15 -
-
This doesn't work. My MSYS terminal is "different" from windows cmd, and running cmd in the MSYS terminal, then npm within it and still the same issue... Commented Sep 3, 2022 at 17:10
I wasted a lot of time on this. My solution is:
- Download the Windows Binary (.zip) from nodejs site (https://nodejs.org/en/download/current/)
- Extract it to some folder
- Add that folder to the
PATH
env variable
-
While with this solution, the .npmrc file would be generated in C:\Users\tom instead of in the $HOME of msys2 shell, how to remedy it?– IcebergCommented Jul 21, 2021 at 6:33
It does work to use the Windows installer, and Node.js helpfully provides bash-script versions of npm
and npx
in C:\Program Files\nodejs\
to help streamline the process.
However, contrary to Cerclanism's comment @ jmgonet's answer, you should not use --full-path
with MinGW, no matter what terminal you're using, since that will by default bring the entire Windows path into your MinGW environment.
(Assuming you're a typical Windows developer with things like MSVC, Windows Python, and etc. install dirs on your path, containing plenty of names that clash with MinGW path members, you can see how that might bite you at some point down the road. My full Windows CMD.exe %PATH%
is 1236 characters! I don't want all that sucked into MinGW.)
Instead, you should add the nodejs install dir to your MinGW shell $PATH
, say by using everyone's favorite ~/.profile
/~/.zprofile
$PATH
-munging trick:
# Append node.js to path
case ${PATH} in
*"/c/program files/nodejs"*)
;;
*)
export PATH="$PATH:/c/program files/nodejs:"
;;
esac
You'll probably also want to set some configuration, since by default Windows npm
will use ${APPDATA}/npm
for prefix
, ${LOCALAPPDATA}/npm-cache
for cache
, C:\Windows\system32\cmd.exe
for shell
, etc.
# To view the full config including all defaults and overrides
npm config ls -l
# To view the active config for the specified environment
npm config list -L {global,user,project}
Maybe I was just confused, but to me it seemed, from what the configs show/say, that setting prefix=
in my user config would override even local installs. (The project-specific ones where you npm install
without --global
, directly into a node_modules
subdir of the current dir.) But after testing, happily I can report that's not the case, so it's safe to override the builtin prefix=
from your $HOME/.npmrc
.
Whether or not you move the cache=
or let it stay at C:\Users\<you>\AppData\Local\npm-cache\
is your call. I'm sure it'll work that way. (Well, maybe not from an MSYS shell, but from MinGW it should be fine.)
There are minor differences I haven't overcome, but the only one that comes to mind right now is:
npm help <command>
opens a browser window to HTML documentation, instead of displaying man page content directly in the terminal like it does on Linux. (Makes sense, as I don't think the manpages are even installed on Windows. Still disconcerting, though.)
You can simply install nvm, then install nodejs through there. In your MSYS2 shell just run the following to download and install nvm. Its better to go directly here and copy the download commands as the version numbers will change in the url.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash
or
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash
then run the following to setup nvm on your bash path:
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
After running those commands you can use nvm install 16
or whatever node major version number you want. Type just nvm
to get a list of available commands.