• 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

How To Update Yarn

Thumbnail for Glory KimGlory Kim

Glory Kim

Software Engineer, Loom

Published: 1/31/2024

About Terminus

Upgrading Yarn globally

Use one of these commands:

 ## Installation Script
 $ curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version [version]
 ## NPM
 $ npm install --global yarn@<specific version>
 ## Homebrew
 $ brew upgrade yarn

Run in Warp

You can see available versions in the official yarn GitHub repository.

Upgrading Yarn for a specific project

Yarn policies were created to upgrade Yarn to a specific version within a project.

 $ yarn policies set-version <version number>

Run in Warp

When running this command, the specified yarn version will be automatically downloaded from the official GitHub repository, and the version number present in the project's configuration file will be updated.

As long as this change has been added and merged into your project, your teammates working on the repository will be able to use a consistent version of Yarn.

Thumbnail for

But what about yarn self-update**?**

You may have seen references to the yarn self-update command across the web. In 2019, the yarn team decided to replace the yarn self-update command with yarn policies set-version. Per the documentation, yarn policies is now the preferred way to upgrade.

Reinstalling Yarn with npm

Certain situations where you have multiple versions of yarn spread across projects may prevent you from upgrading to the intended yarn package. Here is one path to resolving this issue:

 ## Check the version of yarn 
 $ yarn -v
 
 ## Check for the location
 $ which yarn 
 
 ## Remove this reference
 $ rm -rf 
 
 ## Uninstall yarn globally and install the specific version
 $ npm uninstall --global yarn; npm install --global yarn@

Run in Warp

Troubleshooting upgrading Yarn

Although the yarn policies set-version command is relatively stable, you may still encounter issues after upgrading yarn. Here are a few things you can try to do to fix them:

  1. 1. Run the yarn install command again to reinstall the project's dependencies; which may help with compatibility problems.
  2. 2. Verify the yarn.lock file has the contents you expect to see.
  3. 3. Rely on the published release notes of Yarn and the new version for breaking changes and known issues.

If the above steps do not help, you might need to perform a rollback and downgrade the yarn version.

Upgrading From Yarn 1 to Yarn 2

There are inevitable breaking changes and differences between Yarn 1 (Classic) and Yarn 2. For example, yarn upgrade has been renamed to yarn up and yarn install -- production is now yarn workspaces focus --all --production, which requires a separate plugin. 
Here is a quick summary on how to migrate to Yarn 2:

  1. 1. Install Yarn globally to the latest Yarn 1
  2. 2. Navigate to your project directory in the terminal
  3. 3. Within that directory, set the Yarn version to V2 with yarn set version berry- this will download the specified version from the yarn repository, store it within your project, and update the settings.
  4. 4. Run yarn install

Read Yarn's blog post on migrating for more detail, and to understand Yarn 2 limitations and troubleshooting steps.

Written by

Thumbnail for Glory KimGlory Kim

Glory Kim

Software Engineer, Loom

Filed Under

Related Articles

Upgrade Yarn Package(s)

Learn how to update one or more packages to a specific or latest version using the `yarn upgrade` command.

Yarn
Thumbnail for Razvan LudosanuRazvan Ludosanu

Trusted by hundreds of thousands of professional developers

Download Warp to get started

Download for Mac
Request demo
Thumbnail for null