Compare commits
No commits in common. "master" and "v1.1" have entirely different histories.
136
README.md
136
README.md
|
@ -1,105 +1,66 @@
|
|||
# STOP
|
||||
|
||||
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
|
||||
```
|
||||
|
||||
# Easy Install node.js
|
||||
|
||||
| A [Root](https://rootprojects.org) Project |
|
||||
| Sponsored by [ppl](https://ppl.family) |
|
||||
|
||||
Simple node.js installer for macOS and Linux
|
||||
Automated node.js installers for OS X and Ubuntu
|
||||
|
||||
## QuickStart
|
||||
**node.js only** (no dev tools)
|
||||
|
||||
```bash
|
||||
curl -fsL bit.ly/node-installer | bash
|
||||
# install node.js without development dependencies
|
||||
curl -fsSL https://bit.ly/node-installer | bash -s -- --no-dev-deps
|
||||
|
||||
# using wget instead of curl (Ubuntu)
|
||||
wget -nv https://bit.ly/node-installer -O - | bash -s -- --no-dev-deps
|
||||
```
|
||||
|
||||
*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>
|
||||
**node.js + dev tools**
|
||||
|
||||
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 wget
|
||||
wget -nv https://bit.ly/node-installer -O - ./node-installer.sh; bash ./node-installer.sh --dev-deps
|
||||
```
|
||||
|
||||
*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))
|
||||
|
||||
## Installer Options
|
||||
## 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`:
|
||||
### Choosing a specific version
|
||||
|
||||
```bash
|
||||
NODE_VERSION=v10
|
||||
echo "Current node.js version is $(curl -fsSL https://nodejs.org/dist/index.tab | head -2 | tail -1 | cut -f 1)"
|
||||
```
|
||||
|
||||
Usage:
|
||||
|
||||
```bash
|
||||
export NODE_VERSION=v10.10
|
||||
curl -fsSL https://bit.ly/node-installer | bash
|
||||
# To install a specific version rather than defaulting to latest
|
||||
# latest version at time of writing are v8.11.1 and v10.1.0
|
||||
export NODEJS_VER="v10.1.0"
|
||||
```
|
||||
|
||||
### Location
|
||||
### Choosing an install 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`:
|
||||
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_PREFIIX` anyway).
|
||||
|
||||
```bash
|
||||
export NPM_CONFIG_PREFIX=$HOME/.local
|
||||
export NODE_PATH=$NPM_CONFIG_PREFIX/lib/node_modules
|
||||
curl -fsSL https://bit.ly/node-installer | bash
|
||||
export NPM_CONFIG_PREFIX=/tmp/user/local
|
||||
export NODE_PATH=/tmp/user/local/lib/node_modules
|
||||
|
||||
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
|
||||
PATH=$PATH:/tmp/user/local/bin
|
||||
```
|
||||
|
||||
If you want to add the install location to your `PATH`, add `/bin` to the custom location used above and append it like so:
|
||||
|
||||
```bash
|
||||
PATH=$PATH:$HOME/.local/bin
|
||||
```
|
||||
|
||||
### Development Tools
|
||||
|
||||
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.
|
||||
|
||||
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)
|
||||
|
||||
## Notes
|
||||
|
||||
* [OS X](#apple-os-x)
|
||||
|
@ -138,17 +99,18 @@ curl -fsSL https://bit.ly/node-installer -o /tmp/node-installer.sh; bash /tmp/no
|
|||
wget -nv https://bit.ly/node-installer -O /tmp/node-installer.sh; bash /tmp/node-installer.sh --dev-deps
|
||||
```
|
||||
|
||||
### Automatic Version Detection
|
||||
### Other things you should know
|
||||
|
||||
Fun FYI, here's how the latest version is determined:
|
||||
This is what gets installed:
|
||||
|
||||
```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"
|
||||
```
|
||||
* rsync
|
||||
* curl
|
||||
* wget
|
||||
* git
|
||||
* xcode / brew / build-essential / pkg-config / gcc
|
||||
* node (including npm)
|
||||
* jshint
|
||||
|
||||
```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"
|
||||
```
|
||||
**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.
|
||||
|
|
101
install.sh
101
install.sh
|
@ -14,7 +14,7 @@
|
|||
|
||||
# Not every platform has or needs sudo, gotta save them O(1)s...
|
||||
sudo_cmd=""
|
||||
((EUID)) && [[ -z "${ANDROID_ROOT:-}" ]] && sudo_cmd="sudo"
|
||||
((EUID)) && [[ -z "$ANDROID_ROOT" ]] && sudo_cmd="sudo"
|
||||
|
||||
deps_flag="$1"
|
||||
set -e
|
||||
|
@ -33,7 +33,7 @@ NO_FAIL2BAN="nope"
|
|||
OS="unsupported"
|
||||
ARCH=""
|
||||
SETUP_FILE=""
|
||||
my_tmp="$(mktemp -d -t node-installer.XXXXXXXX)"
|
||||
my_tmp=$(mktemp -d)
|
||||
export my_tmp
|
||||
|
||||
clear
|
||||
|
@ -56,38 +56,37 @@ if [ "$(uname | grep -i 'Darwin')" ]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
# Mavericks+ works for all current macOS versions
|
||||
OS='mavericks'
|
||||
|
||||
if [[ "$OSX_MAJOR" -eq 10 ]]; then
|
||||
#
|
||||
# Minor
|
||||
#
|
||||
if [ "$OSX_MINOR" -le 5 ]; then
|
||||
echo "unsupported OS X version (os 10.5-)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Snow
|
||||
if [ "$OSX_MINOR" -eq 6 ]; then
|
||||
OS='snow'
|
||||
fi
|
||||
|
||||
# Lion
|
||||
if [ $OSX_MINOR -eq 7 ]; then
|
||||
OS='lion'
|
||||
fi
|
||||
|
||||
# Mountain Lion
|
||||
if [ "$OSX_MINOR" -eq 8 ]; then
|
||||
OS='mountain'
|
||||
fi
|
||||
if [ "$OSX_MAJOR" -gt 10 ]; then
|
||||
echo "unsupported OS X version (os 11+)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# OS X (10) and macOS (11) should be supported
|
||||
#
|
||||
# Minor
|
||||
#
|
||||
if [ "$OSX_MINOR" -le 5 ]; then
|
||||
echo "unsupported OS X version (os 10.5-)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$OSX_MAJOR" -gt 11 ]; then
|
||||
echo "WARNING: macOS 12+ may or may not be supported"
|
||||
# Snow
|
||||
if [ "$OSX_MINOR" -eq 6 ]; then
|
||||
OS='snow'
|
||||
fi
|
||||
|
||||
# Lion
|
||||
if [ $OSX_MINOR -eq 7 ]; then
|
||||
OS='lion'
|
||||
fi
|
||||
|
||||
# Mountain Lion
|
||||
if [ "$OSX_MINOR" -eq 8 ]; then
|
||||
OS='mountain'
|
||||
fi
|
||||
|
||||
# Mavericks, Yosemite
|
||||
if [ "$OSX_MINOR" -ge 9 ]; then
|
||||
OS='mavericks'
|
||||
fi
|
||||
|
||||
if [ -n "$(sysctl hw | grep 64bit | grep ': 1')" ]; then
|
||||
|
@ -113,8 +112,6 @@ elif [ "$(uname | grep -i 'Linux')" ]; then
|
|||
OS='ubuntu'
|
||||
elif [ "$(cat /etc/issue | grep -i 'elementary OS')" ]; then
|
||||
OS='ubuntu'
|
||||
elif [ "$(cat /etc/issue | grep -i 'Arch ')" ]; then
|
||||
OS='ubuntu'
|
||||
elif [ "$(cat /etc/issue | grep -i 'Debian')" ]; then
|
||||
OS='ubuntu'
|
||||
elif [ "$(cat /etc/issue | grep -i 'Trisquel')" ]; then
|
||||
|
@ -124,15 +121,13 @@ elif [ "$(uname | grep -i 'Linux')" ]; then
|
|||
elif [ "$(cat /etc/issue | grep -i 'Raspbian')" ]; then
|
||||
OS='raspbian'
|
||||
elif [ "$(cat /etc/issue | grep -i 'Fedora')" ]; then
|
||||
OS='ubuntu'
|
||||
OS='fedora'
|
||||
elif [ "$(cat /etc/issue | grep -i 'Marvell')" ]; then
|
||||
OS='marvell'
|
||||
else
|
||||
OS='ubuntu'
|
||||
fi
|
||||
else
|
||||
echo "unsupported unknown os (non-mac, non-linux)"
|
||||
exit 500
|
||||
exit 1
|
||||
fi
|
||||
|
||||
case "${OS}" in
|
||||
|
@ -232,12 +227,6 @@ fi
|
|||
# Which node.js VERSION ? #
|
||||
#########################
|
||||
|
||||
NODE_VERSION=${NODE_VERSION:-}
|
||||
NODEJS_VER=${NODEJS_VER:-}
|
||||
if [ -n "$NODE_VERSION" ]; then
|
||||
NODEJS_VER=$NODE_VERSION
|
||||
fi
|
||||
|
||||
if [ -z "${NODEJS_VER:-}" ]; then
|
||||
# For backwards compat
|
||||
if [ -f "$my_tmp/NODEJS_VER" ]; then
|
||||
|
@ -258,23 +247,12 @@ if [ -n "${NODEJS_VER:-}" ]; then
|
|||
fi
|
||||
fi
|
||||
|
||||
NODEJS_VER="${NODEJS_VER:-v}" # Search for 'v' at the least
|
||||
# sort -rV # will sort by version number, but it appears these are already sorted
|
||||
# tail -n +2 # starts at line two (1-indexed) and all after (omits the csv header with 'version' and such)
|
||||
# cut -f 1 # gets only the first column
|
||||
# head -n 1 # gets only the most recent version
|
||||
my_char="."
|
||||
my_count=$(awk -F"${my_char}" '{print NF-1}' <<< "${NODEJS_VER}")
|
||||
# get the latest version if partial
|
||||
if [ $my_count -ne 2 ]; then
|
||||
if [ "$NODEJS_VER" != "v" ]; then
|
||||
NODEJS_VER="$NODEJS_VER\\."
|
||||
fi
|
||||
if [ -z "${NODEJS_VER:-}" ]; then
|
||||
if [ -n "$(type -p curl)" ]; then
|
||||
NODEJS_VER=$(curl -fsL "$NODEJS_BASE_URL/dist/index.tab" | tail -n +2 | cut -f 1 | grep "^$NODEJS_VER" | head -n 1) \
|
||||
NODEJS_VER=$(curl -fsL "$NODEJS_BASE_URL/dist/index.tab" | head -n 2 | tail -1 | cut -f 1) \
|
||||
|| echo 'error automatically determining current node.js version'
|
||||
elif [ -n "$(type -p wget)" ]; then
|
||||
NODEJS_VER=$(wget --quiet "$NODEJS_BASE_URL/dist/index.tab" -O - | tail -n +2 | cut -f 1 | grep "^$NODEJS_VER" | head -n 1) \
|
||||
NODEJS_VER=$(wget --quiet "$NODEJS_BASE_URL/dist/index.tab" -O - | head -n 2 | tail -1 | cut -f 1) \
|
||||
|| echo 'error automatically determining current node.js version'
|
||||
else
|
||||
echo "Found neither 'curl' nor 'wget'. Can't Continue."
|
||||
|
@ -302,16 +280,14 @@ if [ -e "$node_install_path/bin/node" ]; then
|
|||
# node of some version is already installed
|
||||
if [ "${NODEJS_VER}" == "$($node_install_path/bin/node -v 2>/dev/null)" ]; then
|
||||
echo node ${NODEJS_VER} is already installed
|
||||
exit 0
|
||||
else
|
||||
echo ""
|
||||
echo "HEY, LISTEN:"
|
||||
echo ""
|
||||
echo "node.js is already installed as node $($node_install_path/bin/node -v | grep v)"
|
||||
echo ""
|
||||
echo "to reinstall as ${NODEJS_VER} please first run: rm $node_install_path/bin/node"
|
||||
echo "to reinstall please first run: rm $node_install_path/bin/node"
|
||||
echo ""
|
||||
exit 1
|
||||
fi
|
||||
|
||||
NODEJS_VER=""
|
||||
|
@ -321,8 +297,7 @@ if [ -n "${NODEJS_VER}" ]; then
|
|||
bash "$my_tmp/${INSTALL_FILE}" "${NODEJS_VER}"
|
||||
fi
|
||||
|
||||
mkdir -p $node_install_path/lib/node_modules 2> /dev/null || $sudo_cmd mkdir -p $node_install_path/lib/node_modules
|
||||
chown -R $(whoami) $node_install_path/lib/node_modules 2> /dev/null || $sudo_cmd chown -R $(whoami) $node_install_path/lib/node_modules
|
||||
chown -R $(whoami) $node_install_path/lib/node_modules || $sudo_cmd chown -R $(whoami) $node_install_path/lib/node_modules
|
||||
|
||||
echo ""
|
||||
|
||||
|
@ -383,5 +358,3 @@ if [ "--dev-deps" == "$deps_flag" ]; then
|
|||
|
||||
echo ""
|
||||
fi
|
||||
|
||||
rm -rf "$my_tmp"
|
|
@ -2,14 +2,14 @@
|
|||
|
||||
# Not every platform has or needs sudo, gotta save them O(1)s...
|
||||
sudo_cmd=""
|
||||
((EUID)) && [[ -z "${ANDROID_ROOT:-}" ]] && sudo_cmd="sudo"
|
||||
((EUID)) && [[ -z "$ANDROID_ROOT" ]] && sudo_cmd="sudo"
|
||||
|
||||
set -e
|
||||
set -u
|
||||
set -o pipefail
|
||||
|
||||
if [ -z "${my_tmp-}" ]; then
|
||||
my_tmp="$(mktemp -d -t node-installer.XXXXXXXX)"
|
||||
my_tmp=$(mkdir -p)
|
||||
fi
|
||||
if [ -z "${PREFIX-}" ]; then
|
||||
PREFIX=""
|
||||
|
@ -55,9 +55,9 @@ NODEJS_UNTAR="$my_tmp/${NODEJS_NAME}-${NODEJS_VER}-linux-${ARCH}"
|
|||
if [ -n "${NODEJS_VER}" ]; then
|
||||
echo "installing ${NODEJS_NAME} as ${NODEJS_NAME} ${NODEJS_VER}..."
|
||||
|
||||
if [ -n "$(command -v curl 2>/dev/null | grep curl)" ]; then
|
||||
if [ -n "$(which curl 2>/dev/null)" ]; then
|
||||
curl -fsSL ${NODEJS_REMOTE} -o ${NODEJS_LOCAL} || echo 'error downloading ${NODEJS_NAME}'
|
||||
elif [ -n "$(command -v wget 2>/dev/null | grep wget)" ]; then
|
||||
elif [ -n "$(which wget 2>/dev/null)" ]; then
|
||||
wget --quiet ${NODEJS_REMOTE} -O ${NODEJS_LOCAL} || echo 'error downloading ${NODEJS_NAME}'
|
||||
else
|
||||
echo "'wget' and 'curl' are missing. Please run the following command and try again"
|
||||
|
@ -71,17 +71,10 @@ if [ -n "${NODEJS_VER}" ]; then
|
|||
mv ${NODEJS_UNTAR}/${NODEJS_NAME}-${NODEJS_VER}-linux-${ARCH}/* ${NODEJS_UNTAR}/
|
||||
rm -rf ${NODEJS_UNTAR}/${NODEJS_NAME}-${NODEJS_VER}-linux-${ARCH} # clean up the temporary unzip folder
|
||||
rm ${NODEJS_UNTAR}/{LICENSE,CHANGELOG.md,README.md}
|
||||
if [ -n "$(command -v rsync 2>/dev/null | grep rsync)" ]; then
|
||||
echo $sudo_cmd rsync -Krl "${NODEJS_UNTAR}/" "$node_install_path/"
|
||||
rsync -Krl "${NODEJS_UNTAR}/" "$node_install_path/" 2>/dev/null || $sudo_cmd rsync -Krl "${NODEJS_UNTAR}/" "$node_install_path/"
|
||||
else
|
||||
# due to symlink issues on Arch Linux, don't copy the share directory
|
||||
rm -rf ${NODEJS_UNTAR}/share
|
||||
echo $sudo_cmd cp -Hr "${NODEJS_UNTAR}/*" "$node_install_path/"
|
||||
cp -Hr "${NODEJS_UNTAR}"/* "$node_install_path/" 2>/dev/null || $sudo_cmd cp -Hr "${NODEJS_UNTAR}"/* "$node_install_path/"
|
||||
fi
|
||||
echo $sudo_cmd rsync -a "${NODEJS_UNTAR}/" "$node_install_path/"
|
||||
rsync -a "${NODEJS_UNTAR}/" "$node_install_path/" || $sudo_cmd rsync -a "${NODEJS_UNTAR}/" "$node_install_path/"
|
||||
rm -rf "${NODEJS_UNTAR}"
|
||||
|
||||
chown -R $(whoami) "$node_install_path/lib/node_modules/" 2>/dev/null || $sudo_cmd chown -R $(whoami) "$node_install_path/lib/node_modules/"
|
||||
chown $(whoami) ""$node_install_path"/bin/" 2>/dev/null || $sudo_cmd chown $(whoami) ""$node_install_path"/bin/"
|
||||
chown -R $(whoami) "$node_install_path/lib/node_modules/" || $sudo_cmd chown -R $(whoami) "$node_install_path/lib/node_modules/"
|
||||
chown $(whoami) ""$node_install_path"/bin/" || $sudo_cmd chown $(whoami) ""$node_install_path"/bin/"
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue