node-installer.sh/README.md

144 lines
3.9 KiB
Markdown
Raw Permalink Normal View History

2016-03-28 20:56:29 +00:00
# Easy Install node.js
2017-11-03 20:51:47 +00:00
| Sponsored by [ppl](https://ppl.family) |
2014-12-22 00:10:33 +00:00
2018-09-10 08:19:11 +00:00
Simple node.js installer for macOS and Linux
2014-12-22 00:36:52 +00:00
2018-09-10 07:40:50 +00:00
## QuickStart
2016-03-28 20:56:29 +00:00
```bash
2018-09-10 08:19:11 +00:00
curl -fsL bit.ly/node-installer | bash
2018-09-10 07:40:50 +00:00
```
2018-09-10 08:19:11 +00:00
*Note*: [bit.ly/node-installer](https://bit.ly/node-installer) is a redirect to <https://git.coolaj86.com/coolaj86/node-installer.sh/raw/master/install.sh>
2018-09-10 07:40:50 +00:00
## 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))
2018-09-10 08:19:11 +00:00
## Installer Options
2018-09-10 07:40:50 +00:00
* [x] version
* [x] install location
* [x] tools for building native modules
2018-09-10 08:19:11 +00:00
### Choose Version
2018-09-10 07:40:50 +00:00
2018-09-10 08:19:11 +00:00
The latest version of node is installed by default.
2018-09-10 07:40:50 +00:00
2018-09-10 08:19:11 +00:00
You can choose a specific version by defining `NODE_VERSION` in the format `vX`, `vX.Y`, or `v.X.Y.Z`:
2018-09-10 07:40:50 +00:00
```bash
2018-09-10 08:19:11 +00:00
NODE_VERSION=v10
2018-09-10 07:40:50 +00:00
```
2018-09-10 08:19:11 +00:00
Usage:
2018-09-10 08:20:38 +00:00
```bash
2018-09-10 08:19:11 +00:00
export NODE_VERSION=v10.10
2018-09-10 07:40:50 +00:00
curl -fsSL https://bit.ly/node-installer | bash
```
2018-09-10 08:19:11 +00:00
### Location
2018-09-10 07:40:50 +00:00
By default node will be installed to `/usr/local`, without root if possible.
2014-12-22 00:36:52 +00:00
2018-09-10 08:19:11 +00:00
You can choose a specific location by setting **both** `NPM_CONFIG_PREFIX` **and** `NODE_PATH`:
2018-09-10 07:40:50 +00:00
2018-09-10 08:20:38 +00:00
```bash
2018-09-10 08:21:38 +00:00
export NPM_CONFIG_PREFIX=$HOME/.local
2018-09-10 08:19:11 +00:00
export NODE_PATH=$NPM_CONFIG_PREFIX/lib/node_modules
2018-09-10 07:40:50 +00:00
curl -fsSL https://bit.ly/node-installer | bash
```
2018-09-10 08:19:11 +00:00
If you want to add the install location to your `PATH`, add `/bin` to the custom location used above and append it like so:
2016-03-28 20:35:23 +00:00
2016-03-28 20:56:29 +00:00
```bash
2018-09-10 08:19:11 +00:00
PATH=$PATH:$HOME/.local/bin
2015-01-20 00:09:36 +00:00
```
2018-09-10 08:19:11 +00:00
### Development Tools
2016-03-28 20:56:29 +00:00
2018-09-10 08:19:11 +00:00
If you plan on building or creating native node modules, you'll want to install `gcc`, `pgk-config`, and a few other required tools and niceties.
2017-11-03 21:16:35 +00:00
2018-09-10 08:19:11 +00:00
In fact, it's fairly common for modules to have both native module and pure js dependencies, so you'll probably want (or need) to install these even if you don't plan to use them directly.
2018-05-24 21:34:44 +00:00
2018-09-10 08:19:11 +00:00
* [x] curl & wget
* [x] git
* [x] rsync
* [x] xcode, brew (on macOS), build-essential (Linux)
* [x] gcc, pkg-config
* [x] pkg-config
* [x] node.js, jshint
2017-11-03 21:11:57 +00:00
2018-09-10 08:19:11 +00:00
Pass `--dev-deps` to the installer script and it will use either `brew` (on macOS) or `apt` (on Linux) to install the development tools.
2017-11-03 21:11:57 +00:00
```bash
2018-09-10 08:19:11 +00:00
curl -fsSL https://bit.ly/node-installer | bash -s -- --dev-deps
2018-05-24 21:34:44 +00:00
```
2017-11-03 21:11:57 +00:00
2018-09-10 08:19:11 +00:00
Or, if you don't have `curl` installed yet you can use `wget`:
2018-06-14 21:10:05 +00:00
```bash
2018-09-10 08:19:11 +00:00
wget -nv https://bit.ly/node-installer -O - | bash -s -- --dev-deps
2018-06-14 21:10:05 +00:00
```
2018-09-10 08:19:11 +00:00
### Securing your server
2018-06-14 21:10:05 +00:00
2018-09-10 08:19:11 +00:00
If you're running a node.js server on anything with a public ip address
(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 (which you should also do).
2017-11-03 21:11:57 +00:00
2018-09-10 08:19:11 +00:00
See [The 15-Minute Guide to Secure VPS Access (for the Semi-Paranoid)](https://www.youtube.com/watch?v=YZzhIIJmlE0)
2017-11-03 21:11:57 +00:00
2016-03-28 20:56:29 +00:00
## Notes
2015-01-21 06:33:28 +00:00
2016-03-28 20:56:29 +00:00
* [OS X](#apple-os-x)
* [Ubuntu Linux](#ubuntu-linux)
* [Important Notes](#other-things-you-should-know)
2014-12-22 00:36:52 +00:00
2016-03-28 20:56:29 +00:00
### Apple OS X
2015-01-21 05:45:27 +00:00
First you need to **Install XCode Command Line Tools**
2015-01-21 05:39:46 +00:00
```bash
xcode-select --install
```
2015-01-21 05:45:27 +00:00
Then you need to **Accept the XCode License** by running any command installed by Xcode with sudo. We'll use git.
2015-01-21 05:39:46 +00:00
```bash
sudo git --version
```
You can scroll to the bottom by hitting shift+G (capital G).
2015-01-15 22:59:32 +00:00
Type `agree` and hit enter to accept the license.
2015-01-15 22:59:32 +00:00
2015-12-09 20:40:29 +00:00
Now you can install node.js
2014-12-22 00:36:52 +00:00
2015-01-08 18:39:49 +00:00
```bash
2018-05-12 19:46:57 +00:00
curl -fsSL https://bit.ly/node-installer -o /tmp/node-installer.sh; bash /tmp/node-installer.sh --dev-deps
2014-12-22 00:36:52 +00:00
```
*TODO*: Make it easier to accepting the license (automatic?)
2016-03-28 20:56:29 +00:00
### Ubuntu Linux
2015-01-21 05:39:46 +00:00
```bash
2018-05-12 19:46:57 +00:00
wget -nv https://bit.ly/node-installer -O /tmp/node-installer.sh; bash /tmp/node-installer.sh --dev-deps
```
2018-09-10 08:19:11 +00:00
### Automatic Version Detection
2018-09-10 08:19:11 +00:00
Fun FYI, here's how the latest version is determined:
2014-12-22 00:36:52 +00:00
2018-09-10 08:19:11 +00:00
```bash
NODE_VERSION=$(curl -fsSL https://nodejs.org/dist/index.tab | tail -n +2 | cut -f 1 | head -1 )
echo "The current node.js version is $NODE_VERSION"
```
2015-01-08 18:17:15 +00:00
2018-09-10 08:19:11 +00:00
```bash
BASE_VER="v10\\."
NODE_VERSION=$(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 $NODE_VERSION"
```