How to use the command 'fnm' (with examples)

How to use the command 'fnm' (with examples)

The ‘fnm’ command is a fast Node.js version manager that allows users to easily install, uninstall, and switch between different versions of Node.js. This article will provide examples of various use cases for the ‘fnm’ command.

Use case 1: Install a specific version of Node.js

Code:

fnm install 12.16.1

Motivation: Installing a specific version of Node.js is useful when working on different projects that may require different versions of Node.js. By using ‘fnm install’, you can easily switch between different Node.js versions based on project requirements.

Explanation: The ‘install’ argument is used to install a specific version of Node.js, followed by the version number (e.g. 12.16.1).

Example output:

Downloading Node.js version 12.16.1...
Installing Node.js version 12.16.1...
Node.js version 12.16.1 has been successfully installed.

Use case 2: List all available Node.js versions and highlight the default one

Code:

fnm list

Motivation: It is important to be aware of the available Node.js versions on your system. ‘fnm list’ provides a comprehensive list of installed versions, making it easy to see which versions are available and which one is set as the default.

Explanation: The ’list’ argument is used to display all installed versions of Node.js. The default version is highlighted in the list.

Example output:

Available Node.js versions:
- 10.23.0
- 11.15.0
- 12.16.1 (default)
- 14.15.3

Use case 3: Use a specific version of Node.js in the current shell

Code:

fnm use 12.16.1

Motivation: When working on a project, it is often necessary to use a specific version of Node.js. By using ‘fnm use’, you can switch to the desired version without affecting other projects or the default version.

Explanation: The ‘use’ argument is used to switch to a specific version of Node.js for the current shell. The version number (e.g. 12.16.1) is provided as the argument.

Example output:

Node.js version 12.16.1 is now being used in the current shell.

Use case 4: Set the default Node.js version

Code:

fnm default 14.15.3

Motivation: The default Node.js version is the version automatically used by ‘fnm’ when no specific version is specified. By setting the default version, you can ensure that new shells or projects will use the desired version by default.

Explanation: The ‘default’ argument is used to set the default Node.js version. The version number (e.g. 14.15.3) is provided as the argument.

Example output:

Default Node.js version changed to 14.15.3.

Use case 5: Uninstall a given Node.js version

Code:

fnm uninstall 11.15.0

Motivation: Over time, it may become necessary to uninstall older versions of Node.js to free up disk space or to maintain a clean development environment. ‘fnm uninstall’ enables the removal of specific versions of Node.js.

Explanation: The ‘uninstall’ argument is used to remove a given version of Node.js. The version number (e.g. 11.15.0) is provided as the argument.

Example output:

Node.js version 11.15.0 has been successfully uninstalled.

Conclusion:

The ‘fnm’ command provides a convenient way to manage different versions of Node.js. Whether it’s installing specific versions, switching between them, setting defaults, or uninstalling unnecessary versions, ‘fnm’ offers a simple and efficient solution for managing Node.js versions.

Related Posts

How to use the command 'eval' (with examples)

How to use the command 'eval' (with examples)

The ’eval’ command is used to execute arguments as a single command in the current shell and return its result.

Read More
How to use the command 'rustup target' (with examples)

How to use the command 'rustup target' (with examples)

This command allows you to modify a toolchain’s supported targets in Rust.

Read More
Using the `pio remote` Command (with examples)

Using the `pio remote` Command (with examples)

List all active Remote Agents pio remote agent list Motivation: This command allows you to see a list of all active Remote Agents connected to your platform.

Read More