Overview
All xPack Core Tools are Node.js CLI application
available from the
npmjs.com public repository and are installed
via npm
which runs on top of node
, which is the Node.js
(or Node in short) executable.
Prerequisites
A recent Node.js (>=16.14), since some dependencies require new features. Detailed instructions for each supported platform are available in the next section.
$ node --version
v18.16.0
If this is your first encounter with npm, you need to install the Node.js ECMAScript (JavaScript) run-time. The process is straightforward and does not pollute the system locations; there are two Node versions, LTS (Long Term Service) and Current; generally it is safer to use LTS, especially on Windows.
For Windows, the general procedure is to download the package and install it as usual (see below for details).
The result is a binary program named node.exe
,
that can be used to execute
JavaScript code from the terminal, and a stub named npm.cmd
, executing
the npm-cli.js
script, which is part of the Node.js module that implements
the npm
functionality.
Manual install
node
install
Download the Windows Installer (.msi) from the Node.js download page and install it as usual, with administrative rights.
node-v*-x64.msi
file.The result is a folder like C:\Program Files\nodejs
, added to the
system path since it includes the node.exe
binary.
C:\>where node.exe
C:\Program Files\nodejs\node.exe
C:\>node --version
v18.16.0
npm
update
A version of npm, usually a bit older, comes packed with Node.js.
C:\>where npm.cmd
C:\Program Files\nodejs\npm.cmd
C:\>npm --version
9.6.0
It is recommended to update it to the latest version:
C:\>npm install --global npm@latest
removed 1 package, and changed 60 packages in 5s
27 packages are looking for funding
run `npm fund` for details
Surprisingly, checking the version usually shows the old version:
C:\>where npm.cmd
C:\Program Files\nodejs\npm.cmd
C:\>npm --version
9.6.0
This is because on Windows, by default, global node packages are
installed in the
user home folder, in %APPDATA%\npm
(like C:\Users\ilg\AppData\Roaming\npm
);
and this path is not in the default environment.
C:\>echo %Path%
It must be added manually in front of the current path:
C:\>set Path=%APPDATA%\npm;%Path%
To make this setting persistent, also issue the following:
C:\>setx Path "%APPDATA%\npm;%Path%"
setx
but harmful to set
.cmd.exe
terminal; for PowerShell or other terminals, please adjust
the syntax to match their specifics.After this, the new version of the program should be visible:
C:\>npm --version
9.6.6
Git
Although not mandatory for using the xPack tools alone, on Windows it is recommended to also install the Git for Windows package.
The xPack Core Tools can run either in the Windows cmd.exe
terminal,
or in the Git shell terminal.
PowerShell Execution Policies
Recent Windows versions use PowerShell, which has a more restrictive execution policy intended to prevent the execution of malicious scripts; unfortunately this also prevents the execution of node.js applications.
If you get a message in the console as the one below:
xpm : File C:\Users\...\AppData\Roaming\npm\xpm.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at
https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ xpm init --template @xpack/hello-world-template@latest --property lan ...
+ ~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
The terminal process "C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -Command xpm init --template @xpack/hello-world-template@latest --property language
then run the following command in a PowerShell terminal:
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope CurrentUser
For more details please read the Microsoft about_Execution_Policies page.
Install xpm
Follow the step in the xpm install page.
If you already know what this is all about, issue the following command:
npm install --global xpm@latest
For Unix-like systems, it is highly recommended to use a version manager (see below).
The result is a binary program named node
,
that can be used to execute
JavaScript code from the terminal, and a symbolic link named npm
, pointing to
the npm-cli.js
script, which is part of the Node.js module that implements
the npm
functionality.
node
itself, but will also require administrative rights for using
npm
and xpm
, and these tools fail in various ways when installed
with administrative rights (mostly with problems related to permissions);
to simplify maintenance, the highly recommended method is to install
Node.js/npm in the home folder, using a version manager.Quick instructions
If you know what you’re doing and prefer a shortcut, copy/paste the following script into a terminal (otherwise perform the steps one by one).
mkdir -pv "${HOME}/Downloads/"
curl --output "${HOME}/Downloads/install-nvm-node-npm-xpm.sh" https://raw.githubusercontent.com/xpack/assets/master/scripts/install-nvm-node-npm-xpm.sh
cat "${HOME}/Downloads/install-nvm-node-npm-xpm.sh"
bash "${HOME}/Downloads/install-nvm-node-npm-xpm.sh"
exit
This script will install nvm
(the Node Version Manager), node
,
npm
and xpm
.
nvm
automatically,
the script adds several lines
to the shell initialisation script.Command Line Tools
The system C/C++ headers and most development tools are not in the standard macOS distribution, and need to be installed separately; they are provided by Apple as the separate Command Line Tools package.
If you followed the Quick instructions, it was already installed. Otherwise, to install the Command Line Tools only if they are not already in the expected location, use:
if [ ! -d "/Library/Developer/CommandLineTools/" ]
then
xcode-select --install
fi
install-nvm-node-npm-xpm.sh
script was successful,
the rest of this page is only informative and can be skipped.Install nvm
(node version manager)
Node.js can be installed manually, but for a greater flexibility, on POSIX platforms it is possible to automate this process by using nvm, which not only simplifies the install procedure, but also allows advanced users to install multiple versions of Node.js in parallel. For details, see the Using a Version Manager to install Node.js and npm page.
In short, nvm changes the install
location to ~/.nvm
and allows to install multiple instances of node
in the ~/.nvm/versions/node
folder.
If you have a previous version of npm installed with a local prefix, remove it:
npm config delete prefix
sudo rm -rf /usr/local/lib/node-modules /usr/local/bin/node /usr/local/bin/npm /usr/local/bin/npm
rm -rf ~/Library/npm ~/opt/npm
Also remove ${HOME}/Library/npm/bin
or ${HOME}/opt/npm/bin
from the PATH.
When everything is clean, run the install script:
touch ~/.zshrc
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
This will install the version manager in ~/.nvm
, and add a few lines to the shell profile (.zshrc
, which must be present).
To install the latest node, after updating the shell profile, open a new terminal (to make use of the new environment variables) and issue the following:
% nvm install --lts node
Downloading and installing node v16.18.0...
Downloading https://nodejs.org/dist/v16.18.0/node-v16.18.0-darwin-x64.tar.xz...
############################################################################################# 100.0%
Computing checksum with shasum -a 256
Checksums matched!
Now using node v16.18.0 (npm v8.19.2)
$ nvm ls
v12.22.12
-> v16.18.0
default -> node (-> v16.18.0)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v16.18.0) (default)
stable -> 16.18 (-> v16.18.0) (default)
lts/* -> lts/gallium (-> v16.18.0)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.12
lts/fermium -> v14.20.1 (-> N/A)
lts/gallium -> v16.18.0
$ nvm use node
Now using node v16.18.0 (npm v8.19.2)
$ nvm alias default node
default -> node (-> v16.18.0)
$ node --version
v16.18.0
$ nvm install-latest-npm
Attempting to upgrade to the latest working version of npm...
* Installing latest `npm`; if this does not work on your node version, please report a bug!
changed 16 packages, and audited 212 packages in 1s
11 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
* npm upgraded to: v8.19.2
$ which npm
/Users/ilg/.nvm/versions/node/v16.18.0/bin/npm
--lts
option.To explicitly install a previous version and to switch to it:
% nvm install 12
Downloading and installing node v12.22.12...
Downloading https://nodejs.org/dist/v12.22.12/node-v12.22.12-darwin-x64.tar.xz...
######################################################################################################## 100.0%
Computing checksum with shasum -a 256
Checksums matched!
% nvm ls
v10.24.1
-> v12.22.12
v16.14.2
v16.16.0
default -> 12 (-> v12.22.12)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v16.16.0) (default)
stable -> 16.16 (-> v16.16.0) (default)
lts/* -> lts/gallium (-> N/A)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1
lts/erbium -> v12.22.12
lts/fermium -> v14.20.1 (-> N/A)
lts/gallium -> v16.18.0 (-> N/A)
% nvm use 12
Now using node v12.22.12 (npm v6.14.16)
% nvm alias default 12
default -> 12 (-> v12.22.12)
% node --version
v12.22.12
% nvm install-latest-npm
Attempting to upgrade to the latest working version of npm...
* Installing latest `npm`; if this does not work on your node version, please report a bug!
/Users/ilg/.nvm/versions/node/v12.22.12/bin/npx -> /Users/ilg/.nvm/versions/node/v12.22.12/lib/node_modules/npm/bin/npx-cli.js
/Users/ilg/.nvm/versions/node/v12.22.12/bin/npm -> /Users/ilg/.nvm/versions/node/v12.22.12/lib/node_modules/npm/bin/npm-cli.js
+ npm@8.19.2
added 73 packages from 21 contributors, removed 299 packages and updated 138 packages in 5.001s
* npm upgraded to: v8.19.2
$ which npm
/Users/ilg/.nvm/versions/node/v12.22.12/bin/npm
At any time, to switch between any of the installed versions,
use nvm use <version>
& nvm alias default <version>
.
Install xpm
xpm
is a portable
Node.js command line application.
If you followed the Quick instructions, it was already installed.
Otherwise, to install it, follow the steps in the xpm install page.
If you know what you’re doing and prefer a shortcut, issue the following command:
npm install --global xpm@latest
For Unix-like systems, it is highly recommended to use a version manager (see below).
The result is a binary program named node
,
that can be used to execute
JavaScript code from the terminal, and a symbolic link named npm
, pointing to
the npm-cli.js
script, which is part of the Node.js module that implements
the npm
functionality.
node
itself, but will also require administrative rights for using
npm
and xpm
, and these tools fail in various ways when installed
with administrative rights (mostly with problems related to permissions);
to simplify maintenance, the highly recommended method is to install
Node.js/npm in the home folder, using a version manager.Quick instructions
If you know what you’re doing and prefer a shortcut, copy/paste the following script into a terminal (otherwise perform the steps one by one).
mkdir -pv "${HOME}/Downloads/"
curl --output "${HOME}/Downloads/install-nvm-node-npm-xpm.sh" https://raw.githubusercontent.com/xpack/assets/master/scripts/install-nvm-node-npm-xpm.sh
cat "${HOME}/Downloads/install-nvm-node-npm-xpm.sh"
bash "${HOME}/Downloads/install-nvm-node-npm-xpm.sh"
exit
This script will install nvm
(the Node Version Manager), node
,
npm
and xpm
.
nvm
automatically,
the script adds several lines
to the shell initialisation script.install-nvm-node-npm-xpm.sh
script was successful,
the rest of this page is only informative and can be skipped.Install nvm
(node version manager)
Node.js can be installed manually, but for a greater flexibility, on POSIX platforms it is possible to automate this process by using nvm, which not only simplifies the install procedure, but also allows advanced users to install multiple versions of Node.js in parallel. For details, see the Using a Version Manager to install Node.js and npm page.
In short, nvm changes the install
location to ~/.nvm
and allows to install
multiple instances of node
in the ~/.nvm/versions/node
folder.
If you have a previous version of npm installed with a local prefix, remove it:
sudo rm -rf /usr/local/lib/nodejs
rm -rf ~/opt/npm
npm config delete prefix
Also remove ${HOME}/opt/npm/bin
from the PATH.
When everything is clean, run the install script:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
This will install the version manager in ~/.nvm
, and add a few lines to
the shell profile, for example to .bash_profile
on most
distributions.
To install the latest node, after updating the shell profile, open a new terminal (to make use of the new environment variables) and issue the following:
$ nvm install --lts node
Downloading and installing node v12.13.0...
Downloading https://nodejs.org/dist/v12.13.0/node-v12.13.0-linux-x64.tar.xz...
####################################################################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Creating default alias: default -> lts/* (-> v12.13.0)
$ nvm ls
-> v12.13.0
system
default -> lts/* (-> v12.13.0)
node -> stable (-> v12.13.0) (default)
stable -> 12.13 (-> v12.13.0) (default)
iojs -> N/A (default)
unstable -> N/A (default)
lts/* -> lts/erbium (-> v12.13.0)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.16.2 (-> N/A)
lts/dubnium -> v10.17.0 (-> N/A)
lts/erbium -> v12.13.0
$ nvm use node
Now using node v12.13.0 (npm v6.12.0)
$ node --version
v12.13.0
$ nvm install-latest-npm
Attempting to upgrade to the latest working version of npm...
* Installing latest `npm`; if this does not work on your node version, please report a bug!
/home/ilg/.nvm/versions/node/v12.13.0/bin/npm -> /home/ilg/.nvm/versions/node/v12.13.0/lib/node_modules/npm/bin/npm-cli.js
/home/ilg/.nvm/versions/node/v12.13.0/bin/npx -> /home/ilg/.nvm/versions/node/v12.13.0/lib/node_modules/npm/bin/npx-cli.js
+ npm@6.13.0
added 2 packages from 2 contributors, removed 2 packages and updated 15 packages in 8.68s
* npm upgraded to: v6.13.0
$ which npm
/home/ilg/.nvm/versions/node/v12.13.0/bin/npm
--lts
option.To explicitly install a previous version and to switch to it:
$ nvm install 10
Downloading https://nodejs.org/dist/v10.17.0/node-v10.17.0-linux-x64.tar.xz...
####################################################################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v10.17.0 (npm v6.11.3)
$ nvm ls
-> v10.17.0
v12.13.0
system
default -> lts/* (-> v12.13.0)
node -> stable (-> v12.13.0) (default)
stable -> 12.13 (-> v12.13.0) (default)
iojs -> N/A (default)
unstable -> N/A (default)
lts/* -> lts/erbium (-> v12.13.0)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.16.2 (-> N/A)
lts/dubnium -> v10.17.0
lts/erbium -> v12.13.0
$ nvm use 10
Now using node v10.17.0 (npm v6.11.3)
$ node --version
v10.17.0
$ nvm install-latest-npm
Attempting to upgrade to the latest working version of npm...
* Installing latest `npm`; if this does not work on your node version, please report a bug!
/Users/ilg/.nvm/versions/node/v10.17.0/bin/npm -> /Users/ilg/.nvm/versions/node/v10.17.0/lib/node_modules/npm/bin/npm-cli.js
/Users/ilg/.nvm/versions/node/v10.17.0/bin/npx -> /Users/ilg/.nvm/versions/node/v10.17.0/lib/node_modules/npm/bin/npx-cli.js
+ npm@6.13.0
added 3 packages from 2 contributors, removed 3 packages and updated 20 packages in 3.081s
* npm upgraded to: v6.13.0
$ which npm
/Users/ilg/.nvm/versions/node/v10.17.0/bin/npm
At any time, to switch between any of the installed versions,
use nvm use <version>
.
bash
on
Ubuntu 18 LTS and Manjaro 18; for other shells they may need small
adjustments.git & curl
Although not a requirement for the node/npm/xpm tools themselves,
it is recommended to have these tools installed, especially git
,
since all examples start with cloning projects.
Install them according to the distribution specifics.
For example on Ubuntu and Debian derived distributions, use:
sudo apt-get install --yes git curl
The GCC development headers and libraries
Also not a requirement for the node/npm/xpm tools themselves, if the xPack toolchains are used for software development, including for running tests, the system C/C++ headers and libraries will be needed.
Install them according to the distribution specifics.
For example on Ubuntu and Debian derived distributions, use:
sudo apt-get install --yes g++ libc6-dev libstdc++6
To compile 32-bit application on 64-bit Intel systems, the multilib package is necessary:
sudo apt-get install --yes g++-multilib
For some applications, the kernel headers are also necessary:
sudo apt-get install --yes linux-headers-generic
Install xpm
xpm
is a portable
Node.js command line application.
If you followed the Quick instructions, it was already installed.
Otherwise, to install it, follow the steps in the xpm install page.
If you know what you’re doing and prefer a shortcut, issue the following command:
npm install --global xpm@latest
Miscellaneous
The official page explaining how to install npm in a custom folder is Resolving EACCES permissions errors when installing packages globally.
For less common platforms, it is also possible to install from unofficial builds, or to build it from sources; for more details see the downloads page.