Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Package Management»How to Install Yarn on MacOS

    How to Install Yarn on MacOS

    By RahulSeptember 26, 20223 Mins Read

    Yarn is a new package manager for JavaScript and the primary tool used by Facebook to manage its source code. As of this writing, Yarn has approximately 370 contributors and is used by notable tech companies such as Airbnb, Dropbox, Uber, Google, and Netflix. If you’re reading this article, it means that you’re probably interested in installing Yarn on your Mac so you can use it to manage your personal projects or help teammates collaborate effectively at work.

    Advertisement

    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.

    yarn --version 
    
    1.22.4
    

    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.

    1. Create and initialize a new project
    2. Use yarn init under a empty folder to create new project.

      yarn init 
      

      The command will go through an interactive session asking a 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.
      
    3. Adding a new module
    4. Use yarn add command to install new dependency to your existing application. You need to specify the package name to add. It will also make a entry in package.json as dependency.

      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] 
      
    5. Upgrading a dependency
    6. 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] 
      
    7. Removing a dependency
    8. If any of the packages is not more required, remove it from your application.

      yarn remove [package] 
      
    9. Using yarn install
    10. This will install all the packages dependencies defined in package.json file.

      yarn install 
      

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

    Conclusion

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

    macOS yarn
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    How to Install Postgres on MacOS

    How To Install PostgreSQL on MacOS

    How to Capture Screenshot on macOS

    Capture Screenshots On Your Mac (3 Keyboard Shortcuts)

    Download Google Chrome on MacOS

    How To Install Google Chrome On macOS

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Implementing a Linux Server Security Audit: Best Practices and Tools
    • cp Command in Linux (Copy Files Like a Pro)
    • 15 Practical Examples of dd Command in Linux
    • dd Command in Linux (Syntax, Options and Use Cases)
    • Iptables: Common Firewall Rules and Commands
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.