ubuntu22.04 arrch64版在线安装node

脚本


    #安装node
    #下载node、npm国内镜像(推荐)
    # 判断是否安装了node
    if type -p  node; then
        echo "node has been installed."
    else
        mkdir -p /home/zenglg 
        cd /home/zenglg
        wget https://registry.npmmirror.com/-/binary/node/v10.14.1/node-v10.14.1-linux-arm64.tar.gz
        #解压并重命名文件夹
        tar -xvf  node-v10.14.1-linux-arm64.tar.gz
        rm -rf /usr/local/node
        mv -f node-v10.14.1-linux-arm64 /usr/local/node
        
        #设置环境变量,使其生效 
        # 检查原先是否已配置node环境变量

        checkNodeExist()
        {
            node1=$(grep -n "export NODE_HOME=/usr/local/node" /etc/profile | cut -f1 -d':')
                if [ -n "$node1" ];then
                    sed -i "${node1}d" /etc/profile
                fi
                
            node2=$(grep -n "export PATH=$NODE_HOME/bin:$PATH" /etc/profile | cut -f1 -d':')
                if [ -n "$node2" ];then
                    sed -i "${node2}d" /etc/profile
                fi
        }
        checkNodeExist
        echo "export NODE_HOME=/usr/local/node" >> /etc/profile
        source /etc/profile

        if [[ ${PATH} =~ ${NODE_HOME}/bin ]]; then
            echo " NODE_HOME has been set"
        else
            echo "export PATH=$NODE_HOME/bin:$PATH" >> /etc/profile
            echo "setting NODE_HOME path successful."
        fi

        #保存刷新
        source /etc/profile

    fi 
node -v

出现下图说明安装成功

ubuntu22.04 arrch64版在线安装node_第1张图片

你可能感兴趣的:(ubuntu22.04,node)