• Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us
TecAdmin
Menu
  • Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us

How to Install Yarn on MacOS

Written by Rahul, Updated on November 26, 2020

Yarn is a package manager for for node.js applications. It allows you to create new packages (peace of code to do specific task) and share with the community.

It provides a command line interface to easy to install, update and manage packages for a Node application. This tutorial will help you to install yarn on macOS systems.

Install Yarn on macOS

Choose one of the below given methods to install Yarn on 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 macOS system. Homebrew is an package manager for macOS operating system provides 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 pon 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 secure way to install Yarn on macOS systems.

Check Yarn Version

Once the Yarn installation completed, execute the following command to verify yarn version.

yarn --version 

1.22.4

Using Yarn

As of now, your have successfully install Yarn on macOS system. Let’s explore some basic uses of Yarn command line.

1. Starting a new project

Use yarn init under a empty folder to create new project.

yarn init 

The command will go through an interactive session asking few questions. Input the required values and press Enter. This will generate a package.json file 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.

2. Adding a dependency

Use yarn add command to install new dependency to your existing application. You need to specify package name to add. It will also make a entry in package.json as dependency.

yarn add [package] 

Also you can specify package version or tag to select correct package version instead of latest version.

yarn add [package]@[version] 
yarn add [package]@[tag] 

3. Upgrading a dependency

Use yarn upgrade command to upgrade already installed packages in your application.

yarn upgrade [package] 

You can also specify version or tag name to upgrade to specific versions.

yarn upgrade [package]@[version] 
yarn upgrade [package]@[tag] 

4. Removing a dependency

If any of package is not more required, remove it from your application.

yarn remove [package] 

5. Installing dependencies

This will install all the packages dependencies defined in package.json file.

yarn install 

yarn install is the default action of yarn command without passing any subcommand.

Conclusion

This tutorial explained you to installing yarn on macOS system. Also explored the details to work with yarn package manager.

Share it!
Share on Facebook
Share on Twitter
Share on LinkedIn
Share on Reddit
Share on Tumblr
Share on Whatsapp
Rahul
Rahul
Connect on Facebook Connect on Twitter

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

Leave a Reply Cancel reply

Popular Posts

  • How to Install Python 3.9 on CentOS/RHEL 7 & Fedora 32/31 0
  • How To Install VNC Server on Ubuntu 20.04 1
  • How To Install NVM on macOS with Homebrew 0
  • (Solved) apt-add-repository command not found – Ubuntu & Debian 0
  • How to Install .NET Core on Debian 10 0
© 2013-2020 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy