简体   繁体   English

为什么“ apt-get install nodejs -y”不安装npm?

[英]Why does 'apt-get install nodejs -y' not install npm?

I have the following bitbucket.pipelines.yml : 我有以下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

Having installed node, the build then fails trying to run npm : 安装了节点后,构建将无法尝试运行npm

+ npm install
bash: npm: command not found

I imagine this is because npm is not in the path. 我想这是因为npm不在路径中。 Or something. 或者其他的东西。 My Ubuntu/UNIX skills are not the best. 我的Ubuntu / UNIX技能不是最好的。

How can I add the install to the path? 如何将安装添加到路径?

Update 更新资料

Ok, after a lot of fiddling my YAML now looks like this: 好吧,经过很多摆弄之后,我的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

Now I have a smaller problem. 现在我有一个较小的问题。 lsb-release is not being found, even though the installer installs it correctly. 即使安装程序正确安装,也找不到lsb-release Is this a path issue?; 这是路径问题吗? how can I execute this when I don't know where it's being installed to? 不知道将其安装在哪里时如何执行? It's difficult to debug because it's running in a docker instance on Bitbucket. 调试困难,因为它运行在Bitbucket上的docker实例中。

Ubuntu contains a version of Node.js in its default repositories that can be used but it only includes the node binary. Ubuntu在其默认存储库中包含可使用的Node.js版本,但仅包含节点二进制文件。 If you want to install npm you can do it by typing: 如果要安装npm ,可以通过键入以下内容进行安装:

apt-get install npm

However, I recommend you to add the PPA (personal package archive) maintained by NodeSource. 但是,我建议您添加由NodeSource维护的PPA(个人软件包存档)。 This will probably have more up-to-date versions of Node.js than the official Ubuntu repositories. 与官方的Ubuntu存储库相比,它可能具有更多的Node.js版本。

You need to install the PPA to get access to its contents, and then you can install the nodejs package in the same way that you did above. 您需要安装PPA才能访问其内容,然后可以按照与上述相同的方式安装nodejs软件包。

curl -sL https://deb.nodesource.com/setup | sudo bash -
sudo apt-get install nodejs

Using this option, the nodejs package contains the nodejs binary as well as npm, so you don't need to install npm separately. 使用此选项,nodejs软件包包含nodejs二进制文件以及npm,因此您不需要单独安装npm。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM