Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing nodejs and npm on MSYS2

Tags:

node.js

msys2

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!

like image 267
Ivan Avatar asked Sep 28 '17 15:09

Ivan


People also ask

What is the best way to install Node JS and NPM?

The best way to install Node.js and npm is through Node.js Version Manager, or nvm. With nvm, you can install multiple versions of both the Node.js runtime and npm, and they can all coexist, though you can only specify one active version of either at a time.

Why do I need to update my Node JS and npm version?

Over time, your Node.js and npm versions will get older and some tools may require you to use a newer version. You can go through the same procedure as when you have installed Node.js the first time. I hope this tutorial helped you get started with your Node.js and npm installation on Windows.

How do I install multiple versions of Node JS on Linux?

Using a Node version manager to install Node.js and npm Node version managers allow you to install and switch between multiple versions of Node.js and npm on your system so you can test your applications on multiple versions of npm to ensure they work for users on different versions. OSX or Linux Node version managers

Does NPM work with odejs on Windows?

It does work to use the Windows installer, and Node.js helpfully provides bash-script versions of npm and npx in C:\Program Files odejs\ to help streamline the process.


2 Answers

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:

  1. 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.)
like image 76
FeRD Avatar answered Sep 16 '22 14:09

FeRD


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
like image 21
Ivan Avatar answered Sep 19 '22 14:09

Ivan