How to install Yarn on your CentOS 7 server

How to install Yarn on your CentOS 7 server

Introduction

Yarn is an ultra-fast dependency management application designed to cache the packages it downloads so they never need not be downloaded again. It is a secure and reliable program that parallelizes all operations to boost resource utilization and expedite install times. This tutorial will help you install the Yarn application on your CentOS 7 Virtual Private Server (VPS) or Dedicated Server, from the official Yarn package repository. This provides you with the most recent versions of Yarn. Ready? Let’s get started!

Before you Begin

For this installation to run smoothly you require the following:

Step 1 –
Installing Yarn

To install Yarn, you must first install Node.js on your server.. For this reason, first, issue the commands below to configure the required Nodesource repository, then install Node.js:

$ sudo curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
$ sudo yum install nodejs

Next, execute the commands below to activate the repository for Yarn and import its GPG key:

$ sudo curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
$ sudo rpm --import https://dl.yarnpkg.com/rpm/pubkey.gpg

Once you add the Yarn repository, run the command below to install Yarn:

$ sudo yum install yarn

You can now issue the following command to confirm the installation:

$ sudo yarn --version

This will give you an output showing the Yarn’s version number:

1.10.1

Step 2 –
Using The Yarn Application

You have successfully installed Yarn and its time to learn how to use this application.

Creating A Yarn Project

Creating a Yarn project is easy using the init command. For instance, to create a project called my_project, issue the command below:

$ sudo yarn init my_project

This will give you a new script with several questions as shown below:

yarninitv1.10.1
questionname (vagrant): Linuxize
questionversion (1.0.0): 0.0.1
questiondescription: TestingYarn
questionentrypoint (index.js): 
questionrepositoryurl: 
questionauthor: Linuxize
questionlicense (MIT): 
questionprivate: 
successSavedpackage.json
Donein 20.18s.

Answer the questions accordingly or press ENTER to leave the answers to the default values. Once all the answers are given, the above script will prompt the creation of a new package.json file. This file will contain all the details provided and can be edited at any time.

Adding Dependencies in Yarn

If you find a package that is vital to any of your projects, you must incorporate it into the dependencies before you can use. The yarn add enables you to add the package with ease. The command to add a new package takes two forms: The first allows you to specify only the package’s name,

$ sudo yarn add [package_name]

Whereas the second form, can be used to add a specific version or tag for the package:

$ sudo yarn add [package_name]@[version_or_tag]

Both commands will add the stipulated package and update the files yarn.lock and package.json, that are related to that particular project.

Upgrading A Dependency

The command used to upgrade the Yarn package dependencies is almost similar to the one used to add the dependency. This command takes the form:’

$ sudo yarn upgrade [package_name]

Or

$ sudo yarn upgrade [package_name]@[version_or_tag]

Both commands will upgrade the specified dependency to the most recent version based on the version range in your the package.json file.

Removing A Project Dependency

If you want to expunge a project dependency, simply issue the command below:

$ sudo yarn remove [package_name]

This will remove the specified dependency and update the yarn.lock and package.json files.

Implementing Project Dependencies

If you want to deploy all the available project dependencies as specified on the package.json file, then execute the command below:

$ sudo yarn

Alternatively, you can issue the command below:

$ sudo yarn install

Conclusion

You have successfully installed Yarn on CentOS VPS or Dedicated server. In addition, we have helped you understand the basic Yarn usage commands and it should not be difficult to get started. If you want in-depth details on how to use Yarn, go to the official Yarn documentation web page.

Check out these top 3 VPS services:

Kamatera
£3.07 /mo
Starting price
Visit Kamatera
Rating based on expert review
  • User Friendly
    3.5
  • Support
    3.0
  • Features
    3.9
  • Reliability
    4.0
  • Pricing
    4.3
Hostinger
£2.29 /mo
Starting price
Visit Hostinger
Rating based on expert review
  • User Friendly
    4.7
  • Support
    4.7
  • Features
    4.8
  • Reliability
    4.8
  • Pricing
    4.7
Webdock
£0.80 /mo
Starting price
Visit Webdock
Rating based on expert review
  • User Friendly
    3.8
  • Support
    4.5
  • Features
    4.5
  • Reliability
    4.3
  • Pricing
    4.3
  • Click this link and all your queries to best hosting will end.
 

Part One: How to Monitor Nginx using Elastic Stack on a CentOS 7 VPS or Dedicated Server

This is Part I of a two-part tutorial explaining how to use the different compon
less than a minute
Idan Cohen
Idan Cohen
Marketing Expert

Part Two: How to Monitor Nginx using Elastic Stack on a CentOS 7 VPS or Dedicated Server

This tutorial will explain how to use the different components of the Elastic St
less than a minute
Idan Cohen
Idan Cohen
Marketing Expert

How to Install cPanel on a CentOS 7 VPS or Dedicated Server

This article provides step by step instructions on how to install cPanel on a Vi
less than a minute
Max Ostryzhko
Max Ostryzhko
Senior Web Developer, HostAdvice CTO

How to Install and Configure Linux Malware Detect on CentOS 7

This tutorial will help you install and configure Linux Malware Detect (LMD) on
less than a minute
Eliran Ouzan
Eliran Ouzan
Web Designer & Hosting Expert
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top