Last active
February 13, 2021 19:12
-
-
Save SamKirsch10/7e1081536de0c7d81cb8666cedfdca0c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Took the good bits from sdesalas/node-pi-zero/ | |
# Switches to unofficial repo since armv6 was removed from main downloads | |
# | |
PI_ARM_VERSION=$( | |
uname -a | | |
egrep 'armv[0-9]+l' -o | |
); | |
if [[ "$PI_ARM_VERSION" == "armv6l" ]]; then | |
LATEST_BASE_URL="https://unofficial-builds.nodejs.org/download/release" | |
LATEST_NODEJS_INDEX="${LATEST_BASE_URL}/index.json" | |
else | |
LATEST_BASE_URL="https://nodejs.org/dist" | |
LATEST_NODEJS_INDEX="${LATEST_BASE_URL}/index.json" | |
fi | |
VERSION=$(curl -sS $LATEST_NODEJS_INDEX | egrep $PI_ARM_VERSION | head -n 1 | egrep -o '("version":")(v[0-9]+.[0-9].[0-9])"' | sed 's/"version"://' | tr -d '"') | |
# Creates directory for downloads, and downloads node | |
cd ~/ && mkdir temp && cd temp; | |
wget "${LATEST_BASE_URL}/${VERSION}/node-${VERSION}-linux-${PI_ARM_VERSION}.tar.gz" | |
tar -xzf node-$VERSION-linux-$PI_ARM_VERSION.tar.gz; | |
# Remove the tar after extracing it. | |
sudo rm node-$VERSION-linux-$PI_ARM_VERSION.tar.gz; | |
# This line will clear existing nodejs | |
sudo rm -rf /opt/nodejs; | |
# This next line will copy Node over to the appropriate folder. | |
sudo mv node-$VERSION-linux-$PI_ARM_VERSION /opt/nodejs/; | |
# Remove existing symlinks | |
sudo unlink /usr/bin/node; | |
sudo unlink /usr/sbin/node; | |
sudo unlink /sbin/node; | |
sudo unlink /usr/local/bin/node; | |
sudo unlink /usr/bin/npm; | |
sudo unlink /usr/sbin/npm; | |
sudo unlink /sbin/npm; | |
sudo unlink /usr/local/bin/npm; | |
# Create symlinks to node && npm | |
sudo ln -s /opt/nodejs/bin/node /usr/bin/node; | |
sudo ln -s /opt/nodejs/bin/node /usr/sbin/node; | |
sudo ln -s /opt/nodejs/bin/node /sbin/node; | |
sudo ln -s /opt/nodejs/bin/node /usr/local/bin/node; | |
sudo ln -s /opt/nodejs/bin/npm /usr/bin/npm; | |
sudo ln -s /opt/nodejs/bin/npm /usr/sbin/npm; | |
sudo ln -s /opt/nodejs/bin/npm /sbin/npm; | |
sudo ln -s /opt/nodejs/bin/npm /usr/local/bin/npm; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment