Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
README.md 2.84 KiB
Newer Older
Nicola LIMONGI's avatar
Nicola LIMONGI committed
ECGALAXY nodejs
Nicola LIMONGI's avatar
Nicola LIMONGI committed

Ansible role that installs [Node.js](https://nodejs.org/) globally.
Nicola LIMONGI's avatar
Nicola LIMONGI committed

Requirements
------------

- On Ubuntu, the `gpg-agent` command, which can be provided by `ecgalaxy.common_packages`.
Nicola LIMONGI's avatar
Nicola LIMONGI committed

Role Variables
--------------

- `nodejs_version`: Sets the Node.js version to install ("18.x", "20.x", etc),
using the distribution package manager.
Optionally, in order to install a specific version from a downloadable archive, set the below variables:

- `nodejs_download_url`: The Node.js archive to download (see https://nodejs.org/dist/)
- `nodejs_checksum`: The archive checksum
- `nodejs_install_path`: The path where Node.js will be installed

About Node.js 18.x, 20.x, 22.x and 23.x on Amazon Linux 2
---------------------------------------------------------
Nicola LIMONGI's avatar
Nicola LIMONGI committed

Official Node.js 18.x, 20.x, 22.x and 23.x pre-built binaries cannot be used on Amazon Linux 2,
due to binary incompatibilities (missing glibc symbol versions).

AWS recommends to build those Node.js versions from source, when using Amazon Linux 2 (AL2).

Pre-built Node.js 18x, 20.x, 22.x and 23.x binaries for Amazon Linux 2 can be found at
https://code.europa.eu/ecgalaxy/amazonlinux2-nodejs/-/packages

They are downloaded by this Ansible role (when executed on AL2),
and saved into the `/opt/nodejs/<nodejs_version>` folder.

Symlinks to the Node.js executables are then created in `/usr/local/bin`.

You may want to update your `$PATH` as well, pointing to the `/opt/nodejs/<nodejs_version>/bin` folder.

Usage with `nvm` has been tested successfully; the command `nvm use system` will correctly point to the "global"
Node.js version (saved into `/opt/nodejs/<nodejs_version>`).

You can also execute this role to globally install 18.x, 20.x, 22.x and 23.x then overwrite the contents of
`~/.nvm/versions/node/v<nodejs_version>` for each, which will allow switching from one version to another
Nicola LIMONGI's avatar
Nicola LIMONGI committed
Dependencies
------------

- optional: ecgalaxy.bootstrap
- optional: ecgalaxy.common_packages
Nicola LIMONGI's avatar
Nicola LIMONGI committed

Example Playbook
----------------

    - hosts: all
      roles:
        - ecgalaxy.bootstrap
        - ecgalaxy.common_packages
Nicola LIMONGI's avatar
Nicola LIMONGI committed
        - ecgalaxy.nodejs

To globally install the default Node.js version:

    bash <(curl -s https://code.europa.eu/-/snippets/1/raw/main/ansible-role.sh) ecgalaxy.nodejs

To globally install Node.js 22.x:
    bash <(curl -s https://code.europa.eu/-/snippets/1/raw/main/ansible-role.sh) ecgalaxy.nodejs --extra-vars '{"nodejs_version":"22.x"}'
See [ansible-role](https://code.europa.eu/-/snippets/1) for instructions.

Please verify the script integrity first.

Nicola LIMONGI's avatar
Nicola LIMONGI committed
License
-------

Copyright the European Union 2022.

Licensed under the EUPL-1.2 or later.
Nicola LIMONGI's avatar
Nicola LIMONGI committed

Author Information
------------------

ECGALAXY team.
Nicola LIMONGI's avatar
Nicola LIMONGI committed
NOTE: This role is based on [original work by Jeff Geerling](https://github.com/geerlingguy/ansible-role-nodejs).