为什么'apt-get install nodejs -y'没有安装npm?

ser*_*gpa 1 ubuntu apt-get node.js npm bitbucket-pipelines

我有以下内容bitbucket.pipelines.yml:

image: python:3.5.1

pipelines:
  branches:
    master:
      - step:
          script:
            - apt-get update
            - apt-get install nodejs -y
            - npm install
            - npm run build
            - python get-pip.py
            - pip install boto3==1.3.0
            - python s3_upload.py io-master.fromthiscomesthat.co.uk dist io-master
Run Code Online (Sandbox Code Playgroud)

安装节点后,构建失败尝试运行npm:

+ npm install
bash: npm: command not found
Run Code Online (Sandbox Code Playgroud)

我想这是因为npm不在路上.或者其他的东西.我的Ubuntu/UNIX技能不是最好的.

如何将安装添加到路径?

更新

好吧,经过大量的摆弄我的YAML现在看起来像这样:

image: python:3.5.1

pipelines:
  branches:
    master:
      - step:
          script:
            - apt-get update
            - apt-get install lsb-release -y
            - curl --silent https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -
            - VERSION=node_5.x
            - DISTRO="$(lsb-release -s -c)" # <--- error here
            - echo "deb https://deb.nodesource.com/$VERSION $DISTRO main" | tee /etc/apt/sources.list.d/nodesource.list
            - echo "deb-src https://deb.nodesource.com/$VERSION $DISTRO main" | tee -a /etc/apt/sources.list.d/nodesource.list
            - apt-get update
            - apt-get install nodejs -y
            - npm install
            - npm run build
            - python get-pip.py
            - pip install boto3==1.3.0
            - python s3_upload.py io-master.fromthiscomesthat.co.uk dist io-master
Run Code Online (Sandbox Code Playgroud)

现在我有一个小问题.lsb-release即使安装程序正确安装它,也找不到.这是路径问题吗?当我不知道它的安装位置时,如何执行此操作?它很难调试,因为它在Bitbucket上的docker实例中运行.

小智 5

Ubuntu在其默认存储库中包含一个Node.js版本,可以使用它,但它只包含节点二进制文件.如果要安装npm,可以输入以下命令:

apt-get install npm

但是,我建议您添加由NodeSource维护的PPA(个人包存档).这可能会有比官方Ubuntu存储库更新的Node.js版本.

您需要安装PPA才能访问其内容,然后您可以nodejs像上面那样安装软件包.

curl -sL https://deb.nodesource.com/setup | sudo bash -
sudo apt-get install nodejs
Run Code Online (Sandbox Code Playgroud)

使用此选项,nodejs包中包含nodejs binary和npm,因此您无需单独安装npm.