• Modern UX

    Edit and navigate faster in the terminal with Warp's IDE-like input editor.

  • Warp AI

    AI suggests what commands to run and learns from your documentation.

  • Agent Mode

    Delegate tasks to AI and use natural language on the command line.

  • Warp Drive

    Save and share interactive notebooks, workflows, and environment variables.

  • All Features

Upgrade Yarn Package(s)

Thumbnail for Razvan LudosanuThumbnail for Razvan LudosanuThumbnail for Razvan LudosanuThumbnail for Razvan Ludosanu
Razvan Ludosanu

Razvan Ludosanu

Founder, learnbackend.dev

Published: 5/7/2024

About Terminus

The short answer

To check the currently installed version number of a package, you can use the following yarn list command:

$ yarn list --pattern “package”

Run in Warp

Where the --pattern flag is used to filter the list of packages by pattern.

For example:

 $ yarn list --pattern “express”
└─ express@4.18.2

Run in Warp

To update a package to its latest version available on the npm registry, you can use the yarn upgrade command combined with the --latest flag as follows:

 $ yarn upgrade --latest <package>

Run in Warp

Note that when using the yarn upgrade command, the package.json and yarn.lock files will automatically be updated to reflect the changes made to the dependencies and sub-dependencies of the project.

If you want to update the yarn command-line tool itself, you can read our article on how to update yarn globally.

Easily retrieve this command using Warp’s AI Command Search

If you’re using Warp as your terminal, you can easily retrieve this command using the Warp AI Command Search feature:

Thumbnail for Thumbnail for Thumbnail for Thumbnail for

Entering yarn update package latest version in the AI Command Search will prompt a yarn command that can then quickly be inserted into your shell by doing CMD+ENTER.

Updating a package to a specific version

To update a package to a specific version, you can use the aforementioned yarn upgrade command and append the desired version number (i.e. 1.2.3) or distribution tag (i.e. latest) to the package name using the following syntax:

$ yarn upgrade <package>@<version|tag>

Run in Warp

For example:

$ yarn upgrade express@4.18.2
$ yarn upgrade express@next

Run in Warp

Updating multiple packages at once

To update all the packages of your project to their latest version based on the version range specified in the package.jsonfile, you can use the yarn upgrade command as follows:

 $ yarn upgrade

Run in Warp

Alternatively, to update one or more packages, you can list them as arguments of the `yarn upgrade` command as follows:

$ yarn upgrade <package …>

Run in Warp

For example:

$ yarn upgrade express axios

Run in Warp

Updating packages to the latest tag version

To update one, several, or all the packages of your project to the version matched by the latest tag available on the npm registry, regardless of the version range specified in the package.json file, you can use a combination of the aforementioned yarn upgrade command and the  --latest option flag as follows:

$ yarn upgrade --latest [package …]

Run in Warp

For example, this command will update all the packages:

$ yarn upgrade --latest

Run in Warp

And this command will only update the express and axios packages:

$ yarn upgrade --latest express axios

Run in Warp

Updating sub-dependencies

When updating a top-level package with the yarn update command, its sub-dependencies will automatically be updated in order to ensure compatibility between versions.

However, in some cases, you may want to independently update a sub-dependency without updating the top-level package that relies on it, for example, due to a security fix.

To do so, you can override its current version in the resolutions fields of the package.json file as follows:

{
  "dependencies": {
    "express": 4.3.2
  },
  "resolutions": {
    "body-parser": "2.3.4"
  }
}

Run in Warp

Installing a package to a specific version

By default, the yarn add command will install the latest available version of a package. To install a specific version instead, you can use the following syntax:

$ $ yarn add <package>@<version|tag>

Run in Warp

Where version is a version number (e.g. 1.2.3) and tag is a distribution tag (e.g. latest).

For example:

$ yarn add express@4.18.2
$ yarn add express@next

Run in Warp

Written by

Thumbnail for Razvan LudosanuThumbnail for Razvan LudosanuThumbnail for Razvan LudosanuThumbnail for Razvan Ludosanu
Razvan Ludosanu

Razvan Ludosanu

Founder, learnbackend.dev

Filed Under

Related Articles

How To Update Yarn

How to update yarn and related troubleshooting

Yarn
Thumbnail for Glory KimThumbnail for Glory KimThumbnail for Glory KimThumbnail for Glory Kim
Glory Kim

Trusted by hundreds of thousands of professional developers

Download Warp to get started

Download for Mac
Request demo
Thumbnail for nullThumbnail for nullThumbnail for nullThumbnail for null