dongwei3336
2018-05-12 03:17
浏览 334
已采纳

尝试使用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.

图片转代码服务由CSDN问答提供 功能建议

我在我的Ubuntu 14.04机器上安装了节点:

   apt-get install node 
   
 
 

然而,当我运行

  node -v 
    
 
 

没有输出。

然后我尝试了 apt-get install nodejs ,当我运行时 nodejs -v 我得 v0.10.25

我不确定我做错了什么让节点工作。

我的PHP脚本需要node.js并且我的检查仍然失败:

  if(preg_match(“/ ^ v \ d +。\ d +。  \ d + $ /“,`node -v`)=== 0){
 exit_json([
”error“=>”此机器上未安装节点。“
]); 
}  
   
 
 

如何在14.04上正确安装node.js? 我使用了数字海洋的教程。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • duangong937906 2018-05-12 03:23
    已采纳

    Try install like this :

    curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
    sudo apt-get install -y nodejs
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • dongpu8935 2018-05-12 03:21

    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.

    评论
    解决 无用
    打赏 举报
  • dongwei3172 2018-05-12 03:46

    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
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题