1

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
}
7
  if which node > /dev/null
    then
        echo "node is installed, skipping..."
    else
        # add deb.nodesource repo commands 
        # install node
    fi
  • 2
    I would use the builtin type -P node rather than calling out to an external program. – glenn jackman Jun 8 '16 at 12:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.