Skip to content

Instantly share code, notes, and snippets.

@trajakovic
Last active February 16, 2019 16:55
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 16 You must be signed in to fork a gist
  • Save trajakovic/ad9f91776dea3b495db0 to your computer and use it in GitHub Desktop.
Save trajakovic/ad9f91776dea3b495db0 to your computer and use it in GitHub Desktop.
Install node.js on fedora (23+).(v5.10.1)
#!/usr/bin/env bash
func_check_for_root() {
if [ ! $( id -u ) -eq 0 ]; then
echo "ERROR: $0 Must be run as root, Script terminating" ;exit 7
fi
}
func_check_for_root
#SETUP PARAMS
NODE_VERSION="v5.10.1"
NODE_INT_VERSION="5101"
NODE_FILE=node-${NODE_VERSION}-linux-x64.tar.gz
NODE_FOLDER=node-${NODE_VERSION}-linux-x64
NODE_URI="https://nodejs.org/dist/${NODE_VERSION}/${NODE_FILE}"
cd /usr/lib
if [[ ! -e "${NODE_FOLDER}" ]]; then
#install DevTools for NPM
dnf groupinstall -y 'Development Tools'
dnf install -y gcc-c++
# get node
wget ${NODE_URI}
# extract
tar xvf ${NODE_FILE}
# remove tar
rm ${NODE_FILE} -f
# install alternatives
update-alternatives --install /usr/bin/node node /usr/lib/${NODE_FOLDER}/bin/node ${NODE_INT_VERSION}
update-alternatives --install /usr/bin/npm npm /usr/lib/${NODE_FOLDER}/bin/npm ${NODE_INT_VERSION}
# update $PATH to make `npm install -g` visible
cat <<EOF >> /home/${SUDO_USER:-$USER}/.bashrc
# added by https://gist.github.com/trajakovic/ad9f91776dea3b495db0 - NodeJs 'installer'
export PATH=\$PATH:/usr/lib/${NODE_FOLDER}/bin
EOF
else
echo Looks like node is already installed:
echo ""
update-alternatives --display node
fi
@trajakovic
Copy link
Author

run this with:
wget -qO- https://gist.githubusercontent.com/trajakovic/ad9f91776dea3b495db0/raw/fedora-install-nodejs.sh|sudo bash

@jbrosan
Copy link

jbrosan commented Nov 17, 2015

Hi trajakovic,

Thank you for posting this! I'm new to node.js and found this helpful. Could you possibly post something on setting permissions and exporting the paths for this for Fedora 23?

Thank you again, GREAT WORK!

@candidosouza
Copy link

thanks for the tip

@lemming
Copy link

lemming commented Feb 19, 2016

Looks like packages installed this way create wrong link to binary:

[root@localhost ~]# npm install -g browser-sync
/usr/lib/node-v5.6.0-linux-x64/bin/browser-sync -> /usr/lib/node-v5.6.0-linux-x64/lib/node_modules/browser-sync/bin/browser-sync.js

So you have to add /usr/lib/node-v5.6.0-linux-x64/bin to your $PATH in order to have browser-sync command working.

You can install Node.js v5 with RPM package though: https://nodejs.org/en/download/package-manager/#enterprise-linux-and-fedora

@trajakovic
Copy link
Author

Oh, honestly didn't have clue anyone would use this, it was more like note for myself.

@jbrosan - sorry for late reply
@lemming - you're right, i've updated script.

Copy link

ghost commented Jun 30, 2016

Thank you, great work!

@bnielsen1965
Copy link

Thanks for this script. If you are interested I extended your work into an install script that accepts a command line option for the nodejs version number. And it now has command options for install, uninstall, and a path or removepath command to use as a normal user to add the PATH settings to the user's bashrc settings.

https://gist.github.com/bnielsen1965/722e8883c3b373d9c783e6b85e659a5f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment