在 Ubuntu 16.04 中从源代码安装 node js 8.2.1

在 Ubuntu 16.04 中从源代码安装 node js 8.2.1

我无法在我的 Ubuntu 16.04 中安装 node-v8.2.1-linux-x64.tar.xz。

我正在通过源安装节点-我不想按照以下方式使用合适的解决方案:

如何使用 apt 安装 NodeJS 4?

我收到的信息:-

npm WARN saveError ENOENT: no such file or directory, open 
'/home/ubuntuser/Downloads/node-v8.2.1-linux-x64/lib/package.json'
npm WARN enoent ENOENT: no such file or directory, open 
'/home/vishnu/Downloads/node-v8.2.1-linux-x64/lib/package.json'
npm WARN lib No description
npm WARN lib No repository field.
npm WARN lib No README data
npm WARN lib No license field.

有人可以发布一步一步的安装过程吗?

答案1

您可以使用没有记录- node version manager

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
nvm install v8.2.1

测试node -v:)

答案2

我创建了以下 bash 脚本来安装 nodejs...无需等待 nvm 提供最新版本...cat install_node.sh

#!/bin/bash

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

# export NODE_VER=v8.0.0 # matches meteor 1.4.2.3 # edit this line next time you need to update nodejs
export NODE_VER=v8.2.1

# 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

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

curr_OS=$( uname )

echo curr_OS $curr_OS

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

    export OS_ARCH=darwin-x64

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

    export 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

# put all above export lines into  ~/.bashrc file 

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

相关内容