dongwei3336
dongwei3336
2018-05-12 03:17

尝试使用nodejs时没有输出

已采纳

I installed node on my Ubuntu 14.04 machine with:

apt-get install node

However, when I run

node -v

there is no output.

I then tried apt-get install nodejs, and when I run nodejs -v I get v0.10.25.

I'm not really sure what I'm doing wrong to get node working.

My PHP script requires node.js and my check keeps failing:

if(preg_match("/^v\d+.\d+.\d+$/", `node -v`) === 0){
    exit_json([
        "error" => "Node isn't installed on this machine."
    ]);
}

How can I correctly install node.js on 14.04? I used digital ocean's tutorial.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

3条回答

  • duangong937906 duangong937906 3年前

    Try install like this :

    curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
    sudo apt-get install -y nodejs
    
    点赞 评论 复制链接分享
  • dongwei3172 dongwei3172 3年前

    If you are using Node.js as a developer in you developing machine I advise you to install it using NVM.

    Follow the instructions than add the following to your ~/.bashrc file:

    source ~/.nvm/nvm.sh
    

    After type

    $source ~/.bashrc
    

    This will allow you to use NVM to install the versions you want:

    $nvm install 10
    

    You can install older versions and use whatever one you have installed by typing:

    $nvm use 8.4.0
    
    点赞 评论 复制链接分享
  • dongpu8935 dongpu8935 3年前

    If you want to execute it, make sure you're specifying the full path (or make sure node is in the path.)

    Also, that's a very, very old version of Node.js you've installed.

    点赞 评论 复制链接分享

为你推荐