How to Install and Use NPX on Ubuntu (Ultimate Guide)

NPX is a powerful package runner tool that comes pre-installed with Node.js and npm. It allows users to easily run packages and executables without the need to install them globally on their system. In this ultimate guide, we will walk you through how to install and use NPX on Ubuntu.

Installing NPX on Ubuntu

To install NPX on Ubuntu, you first need to have Node.js and npm installed on your system. If you haven’t already installed them, you can do so by running the following commands in your terminal:

sudo apt update
sudo apt install nodejs npm

Once Node.js and npm are installed, you can easily install NPX by running the following command:

npm install -g npx

This will install NPX globally on your system, allowing you to use it from anywhere on your system.

Using NPX on Ubuntu

Now that NPX is installed on your system, you can start using it to run packages and executables. Here are some common use cases for NPX:

  1. Running packages from the npm registry:

You can use NPX to run packages directly from the npm registry without the need to install them globally. For example, to run the create-react-app package, you can simply run the following command:

npx create-react-app my-app

This will download and run the create-react-app package in a temporary directory without installing it globally on your system.

  1. Running local executables:

You can also use NPX to run local executables that are not installed globally on your system. For example, if you have a local executable called my-script, you can run it using NPX by specifying its path:

npx ./my-script

This will run the my-script executable without the need to install it globally on your system.

  1. Executing specific versions of packages:

You can also use NPX to run specific versions of packages from the npm registry. For example, if you want to run version 1.0.0 of the create-react-app package, you can specify the version number in the command:

npx create-react-app@1.0.0 my-app

This will download and run version 1.0.0 of the create-react-app package without installing it globally on your system.

In conclusion, NPX is a powerful tool that allows you to easily run packages and executables without the need to install them globally on your system. By following the steps outlined in this guide, you can easily install and start using NPX on Ubuntu. Happy coding!