A script to install basic development tools for node (git, node, gcc, pkg-config, etc)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

154 lines
4.1 KiB

# STOP
2 years ago
The install method in this repo still has its place, but this is no longer maintained.
**Update**: Use [Webi](https://webinstall.dev) instead:
```sh
curl https://webinstall.dev/node | bash
```
8 years ago
# Easy Install node.js
7 years ago
5 years ago
| A [Root](https://rootprojects.org) Project |
10 years ago
Simple node.js installer for macOS and Linux
## QuickStart
8 years ago
```bash
curl -fsL bit.ly/node-installer | bash
```
*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>
## 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))
## Installer Options
* [x] version
* [x] install location
* [x] tools for building native modules
### Choose Version
The latest version of node is installed by default.
You can choose a specific version by defining `NODE_VERSION` in the format `vX`, `vX.Y`, or `v.X.Y.Z`:
```bash
NODE_VERSION=v10
```
Usage:
```bash
export NODE_VERSION=v10.10
curl -fsSL https://bit.ly/node-installer | bash
```
### Location
By default node will be installed to `/usr/local`, without root if possible.
You can choose a specific location by setting **both** `NPM_CONFIG_PREFIX` **and** `NODE_PATH`:
```bash
export NPM_CONFIG_PREFIX=$HOME/.local
export NODE_PATH=$NPM_CONFIG_PREFIX/lib/node_modules
curl -fsSL https://bit.ly/node-installer | bash
```
If you want to add the install location to your `PATH`, add `/bin` to the custom location used above and append it like so:
8 years ago
```bash
PATH=$PATH:$HOME/.local/bin
```
### Development Tools
8 years ago
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.
7 years ago
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.
* [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
Pass `--dev-deps` to the installer script and it will use either `brew` (on macOS) or `apt` (on Linux) to install the development tools.
```bash
curl -fsSL https://bit.ly/node-installer | bash -s -- --dev-deps
```
Or, if you don't have `curl` installed yet you can use `wget`:
```bash
wget -nv https://bit.ly/node-installer -O - | bash -s -- --dev-deps
```
### Securing your server
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).
See [The 15-Minute Guide to Secure VPS Access (for the Semi-Paranoid)](https://www.youtube.com/watch?v=YZzhIIJmlE0)
8 years ago
## Notes
9 years ago
8 years ago
* [OS X](#apple-os-x)
* [Ubuntu Linux](#ubuntu-linux)
* [Important Notes](#other-things-you-should-know)
8 years ago
### Apple OS X
9 years ago
First you need to **Install XCode Command Line Tools**
9 years ago
```bash
xcode-select --install
```
9 years ago
Then you need to **Accept the XCode License** by running any command installed by Xcode with sudo. We'll use git.
9 years ago
```bash
sudo git --version
```
You can scroll to the bottom by hitting shift+G (capital G).
9 years ago
Type `agree` and hit enter to accept the license.
9 years ago
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?)
8 years ago
### Ubuntu Linux
9 years ago
```bash
wget -nv https://bit.ly/node-installer -O /tmp/node-installer.sh; bash /tmp/node-installer.sh --dev-deps
```
### Automatic Version Detection
Fun FYI, here's how the latest version is determined:
```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"
```
9 years ago
```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"
```