首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >可以安装node.js版本6

可以安装node.js版本6
EN

Stack Overflow用户
提问于 2016-05-10 19:42:10
回答 2查看 5.8K关注 0票数 6

要安装node 6.x版本,可以使用以下命令:

代码语言:javascript
运行
复制
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs

现在我如何在ansible中做到这一点呢?这里有什么想法吗?

这是我到目前为止所拥有的,但它会安装旧版本

代码语言:javascript
运行
复制
---
- name: Ensure Ubuntu Distro is Supported
  get_url:
    url='https://deb.nodesource.com/node/dists/"{{ ansible_distribution_release }}"/Release'
    dest=/dev/null
  register: distrosupported


- name: Remove Old Chris Lea PPA
  apt_repository:
    repo='ppa:chris-lea/node.js'
    state=absent
  when: distrosupported|success
  ignore_errors: yes

- name: Remove Old Chris Lea Sources
  sudo: yes
  file:
    path='/etc/apt/sources.list.d/chris-lea-node_js-"{{ ansible_distribution_release }}".list'
    state=absent
  when: distrosupported|success
  ignore_errors: yes

- name: Add Nodesource Keys
  sudo: yes
  apt_key:
    url=https://deb.nodesource.com/gpgkey/nodesource.gpg.key
    state=present

- name: Add Nodesource Apt Sources List Deb
  sudo: yes
  apt_repository:
    repo='deb https://deb.nodesource.com/node "{{ ansible_distribution_release }}" main'
    state=present
  when: distrosupported|success

- name: Add Nodesource Apt Sources List Deb Src
  sudo: yes
  apt_repository:
    repo='deb-src https://deb.nodesource.com/node "{{ ansible_distribution_release }}" main'
    state=present
  when: distrosupported|success

- name: Install NodeJS
  sudo: yes
  apt: pkg=nodejs state=latest update_cache=true
  when: distrosupported|success





- debug: msg="{{npm_pkgs}}"


- name: install global npm packages
  sudo: yes
  npm: name={{item}} global=yes state=latest
  with_items: "{{npm_pkgs}}"
EN

回答 2

Stack Overflow用户

发布于 2016-05-10 23:14:49

我使用这个剧本通过nvm(节点版本管理器)安装Node6.1.0:

注意:您可能需要更改播放中的主机和连接。

代码语言:javascript
运行
复制
---
- hosts: localhost
  connection: local 
  vars:
    node_version: 6.1.0
  tasks:
    - name: Download the nvm(node version manager) install script
      get_url: url=https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh dest=/tmp/install.sh

    - name: Install dependencies 
      apt: pkg={{ item }} update_cache=yes cache_valid_time=3600
      with_items:
        - git
        - curl
        - build-essential
        - libssl-dev
      become: yes
      become_user: root

    - name: Execute the nvm install script
      shell: bash install.sh chdir=/tmp executable=/bin/bash

    - name: Register the NVM_DIR
      shell: echo $NVM_DIR
      register: nvm_dir 

    - name: Install the specified node version using the nvm command and set it as default
      shell: . {{ nvm_dir.stdout }}/nvm.sh && nvm install {{ node_version }} && nvm run {{node_version}} --version && nvm alias default {{node_version}}
             creates=~/.nvm/versions/node/v{{ node_version }} 

有关nvm的详细信息,请参阅:https://github.com/creationix/nvm

票数 8
EN

Stack Overflow用户

发布于 2017-09-18 18:59:05

根据原始问题中的代码和helpful comment from @ydaetskcoR,我能够在Ubuntu16.04上安装NodeJS 6.x,如下所示:

代码语言:javascript
运行
复制
- name: Add Nodesource Keys
  become: yes
  apt_key:
    url: https://deb.nodesource.com/gpgkey/nodesource.gpg.key
    state: present

# Note: "xenial" is ubuntu-speak for 16.04
- name: Add Nodesource Apt Sources
  become: yes
  apt_repository:
    repo: '{{ item }}'
    state: present
  with_items:
    - 'deb https://deb.nodesource.com/node_6.x xenial main'
    - 'deb-src https://deb.nodesource.com/node_6.x xenial main'

- name: Install NodeJS and NPM
  become: yes
  apt:
    name: '{{ item }}'
    state: latest
    update_cache: yes
  with_items:
    - nodejs
    - nodejs-legacy
    - npm

为简洁起见,我进行了一些重构,但最重要的是将 _6.x 添加到存储库URL中。

这对我使用Ansible 2.3.2.0很有效

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37137513

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档