global
For Arch, one can use pacman:# pacman -S nodejs npmThese will work in any directory.
project
Suppose a user establishes a folder for their node.js project, and is working from that project directory. During their project, they recall that they need to install this or that module, say, express. The user roots up, runs # npm install express, then descends to user and continues working on their script, or some other operation which calls express. Eventually, to verify the express module's working, the user types "express" at the command line. Here's what would happen.$ expressUnlike pacman, npm is a node.js specific installer with its own directory structure. Node.js is roughly analogous to an independent LaTeX install: you can use $ tlmgr to update or control things, but not until the LaTeX directories are added to PATH. Likewise npm works from the command line, except that one must root-up when using it as an installer (# npm install [some package]). This is because the Arch version of npm places the modules into a root privilege directory /usr/lib/node_modules. This will hinder us throughout anything we do. We can place /usr/lib/node_modules/ in our PATH, which will allow execution, but we can never add or modify files in it. For this reason, I strongly believe that, like LaTeX, node.js should be installed in the HOME directory at user level, never requiring root privileges. If you install node.js with pacman, you'd have to pacman or yaourt every single module installed by node.js, or create PATH additions for each and every one that npm installs. No way, jose.
bash: express: command not found
# pacman -Rs npm nodejs
$ rm -r .npm
nvm
For me, the easiest way to install a user-level node.js application was to use NVM volume manager to import node.js. NVM is upstream from node.js installations, so it can download and install any node.js version, allowing multiple releases to exist simultaneously on a system within the home director: users may select the version they wish to use directly from the user level.The NVM script at the blog above downloads the latest git version of NVM, or just go directly to the install script here. I opened it with a word editor and reviewed it, then ran the script to download NVM.
$ sh ./install.shIn addition to installing NVM at the user level, the install script appends to ~/.bashrc so the PATH is updated. I verified the changes, found them acceptable, and then sourced the .bashrc to activate the PATH change. Next, I verified nvm was detected and ran.
$ source .bashrc
$ nvm
No comments:
Post a Comment