From fd325e7723c6b6f57e8a41eb6aa040399b41bac0 Mon Sep 17 00:00:00 2001 From: Peter Harpending Date: Wed, 12 Oct 2022 01:20:25 -0600 Subject: [PATCH] add npm helper doc --- docs/npm-misc/README.md | 53 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 docs/npm-misc/README.md diff --git a/docs/npm-misc/README.md b/docs/npm-misc/README.md new file mode 100644 index 0000000..fd4dbc7 --- /dev/null +++ b/docs/npm-misc/README.md @@ -0,0 +1,53 @@ +# How to install NPM on Ubuntu 18.04 + +The default `nodejs` package on Ubuntu installs an ancient version of Node/NPM +that often doesn't work properly with contemporary code. + +As of the time of writing, Ubuntu's repository contains Node 8.10.0, which is 6 +years out of date. + +To install the latest version of Node (currently: 18.10.0) + +``` +sudo snap refresh +sudo snap install node --channel 18/stable +``` + +You can use `snap info node` to get more information about the latest available +versions. + +You can use `node --version` to verify you are running the most recent version +of Node. + +``` +$ node --version +v18.10.0 +``` + + +# How to install packages from NPM on unix without using `sudo` + +To install an executable package from NPM (such as the TypeScript compiler), +you use `npm install -g PACKAGE`. By default, this attempts to install +`PACKAGE` in a privileged directory, thus requiring `sudo` to execute +successfully. + +In order to avoid running NPM as root, do the following: + +``` +mkdir ~/.npm-packages +npm config set prefix "${HOME}/.npm-packages" +``` + +Edit `~/.bashrc` or `~/.zshrc` with + +``` +NPM_PACKAGES="${HOME}/.npm-packages" +export PATH=$NPM_PACKAGES/bin:$PATH +``` + +Now, `npm install -g` will install to `~/.npm-packages` + +``` +npm install -g typescript +```