aqua Now Supports Node.js

suzukishunsuke

Shunsuke Suzuki

Posted on September 1, 2024

aqua Now Supports Node.js

aqua is a CLI version manager written in Go.

https://aquaproj.github.io/

As of August 24, 2024, aqua now supports Node.js!

https://aquaproj.github.io/docs/reference/nodejs-support/

How to Manage Node.js Using aqua

You'll need aqua-registry v4.216.0 or later.
To get started, add nodejs/node to your aqua.yaml file.

aqua g -i nodejs/node
aqua i -l
Enter fullscreen mode Exit fullscreen mode

Then you can run commands such as node and npm.

node -v
npm -v
Enter fullscreen mode Exit fullscreen mode

Configure npm preset config

To install tools globally using npm i -g, you need to configure the npm preset config and update the PATH environment variable.

export NPM_CONFIG_PREFIX=${XDG_DATA_HOME:-$HOME/.local/share}/npm-global # Feel free to change this path
export PATH=$NPM_CONFIG_PREFIX/bin:$PATH
Enter fullscreen mode Exit fullscreen mode

Once configured, you can install tools by npm i -g.

npm i -g zx
zx -v
Enter fullscreen mode Exit fullscreen mode

Even if you change the version of Node.js, you'll still be able to execute tools installed by npm i -g.

aqua up node@v20.16.0
zx -v
Enter fullscreen mode Exit fullscreen mode

Why do we need to configure npm preset config?

For more details, check out the related issue.

By default, npm i -g installs tools in the same directory as Node.js, meaning the installation path depends on the Node.js version.
Currently, aqua can't dynamically update the PATH environment variable.
We've considered dynamically updating the PATH environment variable for Node.js, but this feature is highly dependent on the environment (shell), making it difficult to maintain.

  • Bash: $PROMPT_COMMAND
  • Zsh: hook function
  • Fish: ???
  • Powershell: ???
  • etc

We prefer not to implement such a feature.

Moreover, dynamically updating the environment variable works only on interactive shells, not in shell scripts.
For example, changing the Node.js version within a shell script wouldn’t update the PATH variable correctly.

Therefore, we decided to fix the installation directory using npm preset config rather than updating dynamically the PATH environment variable.
This approach has several benefits.

  • It doesn't depend on the environment (shell)
  • It doesn't require adding any feature to aqua itself
💖 💪 🙅 🚩
suzukishunsuke
Shunsuke Suzuki

Posted on September 1, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related