node-installer.sh/README.md

207 lines
4.3 KiB
Markdown

# Easy Install node.js
| Sponsored by [ppl](https://ppl.family) |
Automated node.js installers for macOS and Linux
## QuickStart
**node.js only**
```bash
curl -fsSL https://bit.ly/node-installer | bash
```
*Note*: [bit.ly/node-installer](https://bit.ly/node-installer) simple redirects to <https://git.coolaj86.com/coolaj86/node-installer.sh/raw/master/install.sh>
## Screencast
[How to Setup a VPS for node.js Development](https://www.youtube.com/watch?v=ypjzi1axH2A) - [(3:06 installing node.js](https://www.youtube.com/watch?v=ypjzi1axH2A#t=186))
## Options
* [x] version
* [x] install location
* [x] tools for building native modules
**Version Examples**
By default the latest version will be installed.
A specific version can be defined:
```bash
NODE_VERSION=v10 # Latest of v10
NODE_VERSION=v10.1 # Latest of v10.1
NODE_VERSION=v10.10 # Latest of v10.10
NODE_VERSION=v10.10.0 # Exactly v10.10.0
```
```
export NODE_VERSION=v10
curl -fsSL https://bit.ly/node-installer | bash
```
**Custom Install Location**
By default node will be installed to `/usr/local`, without root if possible.
A custom location can be defined:
```
export NPM_CONFIG_PREFIX=$HOME/.local/
export NODE_PATH=$HOME/.local/
curl -fsSL https://bit.ly/node-installer | bash
```
## Node + Dev Tools
* [x] curl & wget
* [x] rsync
* [x] gcc (via XCode or build-essential)
* [x] pkg-config
* [x] node.js
* [x] jshint
Install node.js and basic development tools - git, node, gcc, pkg-config, etc
```bash
curl -fsSL https://bit.ly/node-installer -o ./node-installer.sh; bash ./node-installer.sh --dev-deps
```
Or with `wget`
```bash
wget -nv https://bit.ly/node-installer -O - ./node-installer.sh; bash ./node-installer.sh --dev-deps
```
## Options
### Choosing a specific version
**Latest**
```bash
export NODEJS_VER=""
```
**Exact**
```bash
export NODEJS_VER="v10.2.1"
```
**Latest of vX.Y.Z**
```bash
export NODEJS_VER="v8.1"
```
**Latest of vX.YY.Z**
```bash
# latest of v8.11.x
export NODEJS_VER="v8.11"
```
**Latest of vX.Y**
```bash
export NODEJS_VER="v10"
```
Fun FYI, here's how the latest version is determined:
```bash
NODEJS_VER=$(curl -fsSL https://nodejs.org/dist/index.tab | tail -n +2 | cut -f 1 | head -1 )
echo "The current node.js version is $NODEJS_VER"
```
```bash
BASE_VER="v10\\."
NODEJS_VER=$(curl -fsSL https://nodejs.org/dist/index.tab | tail -n +2 | cut -f 1 | grep $BASE_VER | head -1 )
echo "Latest node.js $BASE_VER is $NODEJS_VER"
```
### Choosing an install location
Just set BOTH `NODE_PATH` and `NPM_CONFIG_PREFIX`.
The install path will be the preceding `lib/node_modules`
(which you usually want to be the same as `NPM_CONFIG_PREFIX` anyway).
```bash
export NPM_CONFIG_PREFIX=/tmp/usr/local
export NODE_PATH=/tmp/usr/local/lib/node_modules
```
A more realistic example for a self-contained node app:
```bash
export NPM_CONFIG_PREFIX=/opt/my-app
export NODE_PATH=/opt/my-app/lib/node_modules
```
```bash
curl -fsSL https://bit.ly/node-installer -o ./node-installer.sh; bash ./node-installer.sh --dev-deps
```
If you want to add the install location to your `PATH`:
```bash
PATH=$PATH:/tmp/user/local/bin
```
## Notes
* [OS X](#apple-os-x)
* [Ubuntu Linux](#ubuntu-linux)
* [Important Notes](#other-things-you-should-know)
### Apple OS X
First you need to **Install XCode Command Line Tools**
```bash
xcode-select --install
```
Then you need to **Accept the XCode License** by running any command installed by Xcode with sudo. We'll use git.
```bash
sudo git --version
```
You can scroll to the bottom by hitting shift+G (capital G).
Type `agree` and hit enter to accept the license.
Now you can install node.js
```bash
curl -fsSL https://bit.ly/node-installer -o /tmp/node-installer.sh; bash /tmp/node-installer.sh --dev-deps
```
*TODO*: Make it easier to accepting the license (automatic?)
### Ubuntu Linux
```bash
wget -nv https://bit.ly/node-installer -O /tmp/node-installer.sh; bash /tmp/node-installer.sh --dev-deps
```
### Other things you should know
This is what gets installed with the dev dependencies:
* rsync
* curl
* wget
* git
* xcode / brew / build-essential / pkg-config / gcc
* node (including npm)
* jshint
**NOTE**: If you're running a node.js server on an edge server,
I'd highly recommend that you also install `fail2ban` to secure ssh -
especially if you haven't switched your server to use key-only authentication.