Last active
May 10, 2022 07:02
-
-
Save altbdoor/9c801dcad5f11352e3dc346ba9ebaf9c to your computer and use it in GitHub Desktop.
Install nodejs to home directory
This file contains hidden or 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 | |
# install via | |
# bash <(curl -L 'https://gist.githubusercontent.com/altbdoor/9c801dcad5f11352e3dc346ba9ebaf9c/raw/install_node.sh') | |
default_version="14" | |
node_regexp='node-v.+?-linux-x64.tar.xz' | |
read -p "Enter desired major version, or leave blank for latest-v${default_version}.x: " node_version | |
if [[ -z "${node_version}" ]]; then | |
node_version="latest-v${default_version}.x" | |
else | |
node_version="latest-v${node_version}.x" | |
fi | |
echo | |
echo "(!) Installing: ${node_version}" | |
echo | |
read -rsn 1 -p "Press any key to continue" | |
binary_name=$(curl -s "https://nodejs.org/download/release/${node_version}/" | grep -oP "${node_regexp}" | head -1) | |
binary_url="https://nodejs.org/download/release/${node_version}/${binary_name}" | |
mkdir ~/nodejs | |
cd ~/nodejs | |
curl -sOL "$binary_url" | |
tar xJf "${binary_name}" | |
rm "${binary_name}" | |
cd "${binary_name/.tar.xz/}/bin" | |
node_path=$(pwd) | |
sudo ln -s "${node_path}/node" /usr/bin/node | |
echo "Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment