Skip to main content

Install NPX on Ubuntu and Use it

Enhanced Node package experience with NPX on Ubuntu.

Sagar Sharma

The NPX is a package runner for NPM which lets you execute packages without even installing them but the question is how you install NPX in Ubuntu?

The answer is straightforward. It comes bundled with NPM so if you've NPM installed on your system, you can use it without any additional steps.

So let's start with the installation.

How to install NPX in Ubuntu

To install NPX in Ubuntu, all you have to do is install NPM as it comes bundled with it and can be installed using the following command:

sudo apt install npm

Once done, you can check the installed version of NPX using the following command:

npx -v
Check the installed version of NPX in Ubuntu

There you have it!

How to use NPX in Ubuntu

In this section, I will be sharing some practical examples of how you can get the most out of the NPX while working with NodeJS projects.

Don't worry, using NPX is quite easy and won't give you headaches 😉.

1. Running a locally installed package

By far this is the most famous way to use the NPX command to run a package installed locally using the NPM package manager.

For that, all you have to do is execute the npx command in following manner:

npx <package_name>

To showcase this, first, I will install webpack package using the NPM:

npm i -D webpack
Install packages using NPM in Ubuntu

Once done, I will use the npx command to run the webpack:

npx webpack

2. Use a package without local installation

To use a package without installation, all you have to do is append the package name with the npx command as shown:

npx <package_name>

For example, here, first, I removed the recently installed package cowsay:

npm rm --silent cowsay

Then used the npx command to invoke the cowsay utility to print "MAGIC":

npx cowsay "MAGIC"
use packages without installing them through NPX in Ubuntu

3. Create a new React app

It requires Node 14 or higher so here's how to upgrade Node to the latest version in Ubuntu.

You can use the create-react-app package with the npx command to create a new React app.

For example, here, I created a new React app my-app using the following command:

npx create-react-app my-app

Once executed, it will check if your system has create-react-app or not and if not, it will install the latest one and then create a new React app called my-app:

Create a new react app using the npx command

Pretty quick. Right?

Wrapping Up...

This was a quick guide on how you can install and use NPX on Ubuntu where I've mentioned some practical usage of the NPX command.

I hope you will find this guide helpful and if you have any queries, feel free to leave a comment.

Sagar Sharma