2

I installed node 8.0.0 on Ubuntu then followed this answer to make it work but now when typing node -v it says v4.7.2. I'd like to have v.8. The one I'm trying to install. Is it a problem with the symlink or what's up ?

(Ubuntu 17:04)

Ced
  • 15,847
  • 14
  • 87
  • 146
  • 1
    https://nodejs.org/en/download/package-manager/ – Brahma Dev Sep 09 '17 at 01:27
  • @BrahmaDev yup I posted the question after following the instructions on that link. I'd recommend following the instructions in the answer below instead. – Ced Sep 09 '17 at 04:35

1 Answers1

2

I suggest you remove the ubuntu package

sudo apt-get remove --purge nodejs-*

then execute below shell script to install nodejs ... you must update your ~/.bashrc with a copy N paste of the lines mentioned in below ... vi install_node.sh

#!/bin/bash

# ............... top of cut  ........................  install_node.sh

export NODE_VER=v8.0.0  # see available versions at https://nodejs.org/dist/

# pick parent dir of nodejs install  ... comment out or remove ONE of below
# export CODE_PARENT_DIR=/opt/code  # root owned dir ... requires you to sudo prior to npm install going forward
export CODE_PARENT_DIR=${HOME}    # RECOMMENDED execute as yourself including npm install

# ......... following env vars are OK no edits needed

curr_OS=$( uname )

if [[ "${curr_OS}" == "Darwin" ]]; then

    OS_ARCH=darwin-x64

elif [[ "${curr_OS}" == "Linux" ]]; then

    OS_ARCH=linux-x64
else
    echo "ERROR - failed to recognize OS $curr_OS"
    exit 5
fi

if [[ -z ${CODE_PARENT_DIR} ]]; then

    echo "ERROR - failed to see env var CODE_PARENT_DIR"
    exit 5
fi

export NODE_CODEDIR=${CODE_PARENT_DIR}/nodejs
export COMSUFFIX=tar.gz
export NODE_NAME=node-${NODE_VER}
export NODE_PARENT=${NODE_CODEDIR}/${NODE_NAME}-${OS_ARCH} 

export PATH=${NODE_PARENT}/bin:${PATH}
export NODE_PATH=${NODE_PARENT}/lib/node_modules

# ............... end of cut  ........................  install_node.sh

# copy and paste above from ... top of cut ... to here into your file ~/.bashrc   

echo
echo "NODE_CODEDIR $NODE_CODEDIR<--"
echo

echo "mkdir -p ${NODE_CODEDIR}"
echo
      mkdir -p ${NODE_CODEDIR}
echo

echo "cd ${NODE_CODEDIR}"
      cd ${NODE_CODEDIR}
echo

# this is compiled code NOT source

[ -f ${NODE_NAME}-${OS_ARCH}.${COMSUFFIX} ] && rm ${NODE_NAME}-${OS_ARCH}.${COMSUFFIX} # if file exists remove

echo "wget -q --show-progress https://nodejs.org/download/release/${NODE_VER}/${NODE_NAME}-${OS_ARCH}.${COMSUFFIX}"
      wget -q --show-progress https://nodejs.org/download/release/${NODE_VER}/${NODE_NAME}-${OS_ARCH}.${COMSUFFIX}
echo

echo "tar -C ${NODE_CODEDIR} -xf ${NODE_NAME}-${OS_ARCH}.${COMSUFFIX}"
      tar -C ${NODE_CODEDIR} -xf ${NODE_NAME}-${OS_ARCH}.${COMSUFFIX}
echo

[ -f ${NODE_NAME}-${OS_ARCH}.${COMSUFFIX} ] && rm ${NODE_NAME}-${OS_ARCH}.${COMSUFFIX} # if file exists remove

# ...........  done ........... #

which node

node --version

# ....  bottom of file   install_node.sh
Scott Stensland
  • 26,870
  • 12
  • 93
  • 104
  • 1
    That was a breeze thanks. Gonna update question title so more people can find this as I had issues finding good informations on how to install node on ubuntu – Ced Sep 08 '17 at 21:50
  • so all you have to do is export packets in ubuntu when you confront issues like these @Ced , nice answer. – Ahmed Can Unbay Sep 08 '17 at 21:50