How to Install Yarn on macOS: 3 Easy Methods
Installing Yarn on macOS
You can install Yarn on macOS using different methods. Here are the most common ways:
1. Install Yarn via Homebrew
Homebrew is a package manager for macOS that simplifies the installation of software.
- Step 1: Install Homebrew
If you don’t have Homebrew, install it by running this in the Terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- Step 2: Install Yarn
After Homebrew is installed, you can install Yarn:
brew install yarn
- Step 3: Verify Installation
Check the Yarn version to ensure it’s correctly installed:
yarn --version
2. Install Yarn Using npm
If Node.js and npm are already installed on your machine, you can use npm to install Yarn globally.
- Step 1: Install Yarn
Run the following command in the Terminal:
npm install -g yarn
- Step 2: Verify Installation
Confirm Yarn is installed by checking its version:
yarn --version
3. Install Yarn via Official Script
For a direct installation from Yarn’s website, you can use their official script.
- Step 1: Run the Script
Execute the following command to download and run the installation script:
curl -o- -L https://yarnpkg.com/install.sh | bash
- Step 2: Update Your PATH (if needed)
The script may suggest adding Yarn to yourPATH
. Typically, you would add this line to your shell profile file (.bash_profile
,.zshrc
, etc.):
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
- Afterward, reload the shell configuration:
source ~/.bash_profile # For Bash source ~/.zshrc # For Zsh
- Step 3: Verify Installation
Ensure Yarn was successfully installed by running:
yarn --version
Conclusion
You now have three ways to install Yarn on macOS: using Homebrew, npm, or the official installation script. Choose the method that works best for you and ensure Yarn is ready to use by checking its version. If you encounter issues or need further assistance, feel free to reach out!