Shell – the most efficient way to check if Node is currently installed

node.jsshell-script

I am writing a script that will first check if Node is currently installed, if not it will install the latest version of Node. If it is installed, then it will proceed to another function to update it.

My current script:

#!/bin/bash

function isNodeInstalled() {
    clear
    echo "Checking if Node is installed ..."
    if command --version node &>/dev/null; then
        echo "Installing Node ..."
        curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
        sudo apt-get install nodejs -y
        echo "Node has been installed."
        sleep 5
        updateNode
    else
        echo "Node has already been installed."
        sleep 5
        updateNode
    fi
}

Best Answer

  if which node > /dev/null
    then
        echo "node is installed, skipping..."
    else
        # add deb.nodesource repo commands 
        # install node
    fi
Related Question