In this tutorial, we’ll show you how to install Yarn on Mac OS in five simple steps.
Installing Yarn on macOS
Choose one of the below-given methods to install Yarn on the macOS system. All the methods are secure and easy to follow.
- Method 1 – Using Homebrew
You can install Yarn using the Homebrew package manager on the macOS system. Homebrew is a package manager for macOS operating system that provides an easier way to install and manage packages on your system.
To install Yarn on macOS, open a terminal and type:
brew install yarn
Make sure you have installed Homebrew on your macOS system.
- Method 2 – Using Shell Script
Another way to easily install Yarn on macOS. This is a shell script provided officially for installing Yarn on different Unix/Linux operating systems.
You can install Yarn by running the following code in your terminal:
curl -o- -L https://yarnpkg.com/install.sh | bash
The script will verify the GPG signature first before the installation. So it is also a secure way to install Yarn on macOS systems.
Check Yarn Version
Once the Yarn installation is completed, execute the following command to verify the yarn version.
Working with Yarn Package Manager
As of now, you have successfully installed Yarn on the macOS system. Let’s explore some basic uses of the Yarn command line.
- Create and initialize a new project
yarn initunder a empty folder to create new project.
The command will go through an interactive session asking a few questions. Input the required values and press Enter. This will generate a
package.jsonfile in current directory.
yarn init v1.22.4 question name (new_project): my-package question version (1.0.0): question description: Test package question entry point (index.js): question repository url: https://github.com/tecadmin/my-yarn-package question author: Rahul question license (MIT): question private: success Saved package.json Done in 84.90s.
- Adding a new module
yarn addcommand to install new dependency to your existing application. You need to specify the package name to add. It will also make a entry in
yarn add [package]
Also, you can specify the package version or tag to select the correct package version instead of the latest version.
yarn add [package]@[version]
yarn add [package]@[tag]
- Upgrading a dependency
Use the yarn upgrade command to upgrade already installed packages in your application.
yarn upgrade [package]
You can also specify a version or tag name to upgrade to specific versions.
yarn upgrade [package]@[version]
yarn upgrade [package]@[tag]
- Removing a dependency
If any of the packages is not more required, remove it from your application.
yarn remove [package]
This will install all the packages dependencies defined in
yarn install is the default action of the yarn command without passing any subcommand.
This tutorial explained to you to install yarn on the macOS system. Also explored the details to work with the yarn package manager.