What is yarn linux

Using Yarn on Ubuntu and Other Linux Distributions

Yarn is an open source JavaScript package manager developed by Facebook. It is an alternative or should I say improvement to the popular npm package manager. Facebook developers’ team created Yarn to overcome the shortcomings of npm . Facebook claims that Yarn is faster, reliable and more secure than npm .

Like npm, Yarn provides you a way to automate the process of installing, updating, configuring, and removing packages retrieved from a global registry.

The advantage of Yarn is that it is faster as it caches every package it downloads so it doesn’t need to download it again. It also parallelizes operations to maximize resource utilization. Yarn also uses checksums to verify the integrity of every installed package before its code is executed. Yarn also guarantees that an install that worked on one system will work exactly the same way on any other system.

If you are using nodejs on Ubuntu, probably you already have npm installed on your system. In that case, you can use npm to install Yarn globally in the following manner:

However, I would recommend using the official way to install Yarn on Ubuntu/Debian.

Installing Yarn on Ubuntu and Debian [The Official Way]

Yarn JS

The instructions mentioned here should be applicable to all versions of Ubuntu such as Ubuntu 18.04, 16.04 etc. The same set of instructions are also valid for Debian and other Debian based distributions.

Since the tutorial uses Curl to add the GPG key of Yarn project, make sure to install curl on Ubuntu first.

The above command will install Curl if it wasn’t installed already. Now that you have curl, you can use it to add the GPG key of Yarn project in the following fashion:

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -

After that, add the repository to your sources list so that you can easily upgrade the Yarn package in future with the rest of the system updates:

sudo sh -c 'echo "deb https://dl.yarnpkg.com/debian/ stable main" >> /etc/apt/sources.list.d/yarn.list'

You are set to go now. Update Ubuntu or Debian system to refresh the list of available packages and then install yarn:

sudo apt update sudo apt install yarn

This will install Yarn along with nodejs. Once the process completes, verify that Yarn has been installed successfully. You can do that by checking the Yarn version.

For me, it showed an output like this:

This means that I have Yarn version 1.12.3 installed on my system.

Using Yarn

I presume that you have some basic understandings of JavaScript programming and how dependencies work. I am not going to go in details here. I’ll show you some of the basic Yarn commands that will help you getting started with it.

Читайте также:  Linux операционная система какая страна

Creating a new project with Yarn

Like npm , Yarn also works with a package.json file. This is where you add your dependencies. All the packages of the dependencies are cached in the node_modules directory in the root directory of your project.

In the root directory of your project, run the following command to generate a fresh package.json file:

It will ask you a number of questions. You can skip the questions r go with the defaults by pressing enter.

yarn init yarn init v1.12.3 question name (test_yarn): test_yarn_proect question version (1.0.0): 0.1 question description: Test Yarn question entry point (index.js): question repository url: question author: abhishek question license (MIT): question private: success Saved package.json Done in 82.42s.

With this, you get a package.json file of this sort:

Now that you have the package.json, you can either manually edit it to add or remove package dependencies or use Yarn commands (preferred).

Adding dependencies with Yarn

You can add a dependency on a certain package in the following fashion:

For example, if you want to use Lodash in your project, you can add it using Yarn like this:

yarn add lodash yarn add v1.12.3 info No lockfile found. [1/4] Resolving packages… [2/4] Fetching packages… [3/4] Linking dependencies… [4/4] Building fresh packages… success Saved lockfile. success Saved 1 new dependency. info Direct dependencies └─ [email protected] info All dependencies └─ [email protected] Done in 2.67s.

And you can see that this dependency has been added automatically in the package.json file:

By default, Yarn will add the latest version of a package in the dependency. If you want to use a specific version, you may specify it while adding.

As always, you can also update the package.json file manually.

Upgrading dependencies with Yarn

You can upgrade a particular dependency to its latest version with the following command:

It will see if the package in question has a newer version and will update it accordingly.

You can also change the version of an already added dependency in the following manner:

You can also upgrade all the dependencies of your project to their latest version with one single command:

It will check the versions of all the dependencies and will update them if there are any newer versions.

Removing dependencies with Yarn

You can remove a package from the dependencies of your project in this way:

Install all project dependencies

If you made any changes to the project.json file, you should run either

to install all the dependencies at once.

How to remove Yarn from Ubuntu or Debian

I’ll complete this tutorial by mentioning the steps to remove Yarn from your system if you used the above steps to install it. If you ever realized that you don’t need Yarn anymore, you will be able to remove it.

Use the following command to remove Yarn and its dependencies.

You should also remove the Yarn repository from the repository list:

sudo rm /etc/apt/sources.list.d/yarn.list

The optional next step is to remove the GPG key you had added to the trusted keys. But for that, you need to know the key. You can get that using the apt-key command:

Warning: apt-key output should not be parsed (stdout is not a terminal) pub rsa4096 2016-10-05 [SC] 72EC F46A 56B4 AD39 C907 BBB7 1646 B01B 86E5 0310 uid [ unknown] Yarn Packaging [email protected] sub rsa4096 2016-10-05 [E] sub rsa4096 2019-01-02 [S] [expires: 2020-02-02]

The key here is the last 8 characters of the GPG key’s fingerprint in the line starting with pub.

Читайте также:  Остановить команду ping linux

So, in my case, the key is 86E50310 and I’ll remove it using this command:

You’ll see an OK in the output and the GPG key of Yarn package will be removed from the list of GPG keys your system trusts.

I hope this tutorial helped you to install Yarn on Ubuntu, Debian, Linux Mint, elementary OS etc. I provided some basic Yarn commands to get you started along with complete steps to remove Yarn from your system.

I hope you liked this tutorial and if you have any questions or suggestions, please feel free to leave a comment below.

Источник

What is yarn linux

Learn Latest Tutorials

Splunk tutorial

SPSS tutorial

Swagger tutorial

T-SQL tutorial

Tumblr tutorial

React tutorial

Regex tutorial

Reinforcement learning tutorial

R Programming tutorial

RxJS tutorial

React Native tutorial

Python Design Patterns

Python Pillow tutorial

Python Turtle tutorial

Keras tutorial

Preparation

Aptitude

Logical Reasoning

Verbal Ability

Company Interview Questions

Artificial Intelligence

AWS Tutorial

Selenium tutorial

Cloud Computing

Hadoop tutorial

ReactJS Tutorial

Data Science Tutorial

Angular 7 Tutorial

Blockchain Tutorial

Git Tutorial

Machine Learning Tutorial

DevOps Tutorial

B.Tech / MCA

DBMS tutorial

Data Structures tutorial

DAA tutorial

Operating System

Computer Network tutorial

Compiler Design tutorial

Computer Organization and Architecture

Discrete Mathematics Tutorial

Ethical Hacking

Computer Graphics Tutorial

Software Engineering

html tutorial

Cyber Security tutorial

Automata Tutorial

C Language tutorial

C++ tutorial

Java tutorial

.Net Framework tutorial

Python tutorial

List of Programs

Control Systems tutorial

Data Mining Tutorial

Data Warehouse Tutorial

Javatpoint Services

JavaTpoint offers too many high quality services. Mail us on h[email protected], to get more information about given services.

  • Website Designing
  • Website Development
  • Java Development
  • PHP Development
  • WordPress
  • Graphic Designing
  • Logo
  • Digital Marketing
  • On Page and Off Page SEO
  • PPC
  • Content Development
  • Corporate Training
  • Classroom and Online Training
  • Data Entry

Training For College Campus

JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected].
Duration: 1 week to 2 week

Like/Subscribe us for latest updates or newsletter RSS Feed Subscribe to Get Email Alerts Facebook Page Twitter Page YouTube Blog Page

Источник

How to Install Yarn on Ubuntu 22.04

How to Install Yarn on Ubuntu 22.04

Package Manager is a tool that installs, updates and manages the software packages you need. with the help of such tools, you can always have the latest version of the libraries you need with your software, and without having to search and check their packages and peripherals, you can only think about developing the core of your software. Yarn also is a package manager and In this article, we are going to teach you how to install Yarn on Ubuntu 22.04. Also, you can visit the packages available in Eldernode if you wish to purchase a Linux VPS Hosting.

What is Yarn?

Yarn stands for Yet Another Resource Negotiator and is a package manager for Node.js in JavaScript that replaces NPM. The Yarn has been developed by the company and the developer to improve and fix the problems that exist in NPM. The Yarn has been developed by Facebook, Google, Exponent, and Tilde. Yarn lets users use their code and share it with other developers around the world. Also, it allows you to use other developers’ solutions to a variety of problems and makes software development easier for you.

Yarn Features

  • Install packages from the local cache of your system without the need for Internet
  • Install packages in parallel
  • Bind the package version firmly
  • High speed in installing packages
  • Simple and readable commands in CLI
  • Provide more capabilities in the field of package management
  • Has different plugins
Читайте также:  Примеры bash скриптов linux

Yarn on Ubuntu 22.04

Install Yarn on Ubuntu 22.04

Before installing Yarn, you need to install npm (Node Package Manager) on your Ubuntu 22.04 system. npm comes with Node.js.

You can install Node.js with the help of the NodeSource repository. First of all open terminal and set up the NodeSource repository for the desired Node.js version.

To set up NodeSource repository 16.x (LTS):

wget -qO- https://deb.nodesource.com/setup_16.x | sudo -E bash

To set up NodeSource repository 18.x (Current Version):

wget -qO- https://deb.nodesource.com/setup_18.x | sudo -E bash

Now install Node.js and npm by running the following command:

sudo apt install -y nodejs

You can check the Node.js version with the following command:

Also, you can check the npm version by entering the following command:

Now it’s time to install Yarn. To do this, run the following command:

sudo npm install --global yarn

You can check the Yarn version with the following command:

In this step, go to your existing project directory with the help of the following command:

Now you need to install the latest Yarn binary for your project by entering the following command:

Then again check the Yarn version with the following command:

The received output indicates that your project has the latest version of Yarn.

How to Use Yarn on Ubuntu 22.04

The following command can guide you with the existing command:

You can create a directory with the help of the following command:

mkdir my_project && cd my_project

To create a new project, just run the following command:

After entering the above command, you will be asked a series of questions related to your project, which you can use the default values by pressing Enter. The above command also puts package.json, which contains the project information that you provided, and yarn.lock, which contains all the information about the project dependencies.

To add a dependency to your project, you can run the following command:

yarn add (package-name)@(version)

The above command downloads and installs dependency packages and updates dependency details in package.json and yarn.lock.

You can use the following command to install all the dependencies of your projects:

To upgrade the dependency of your project, enter the following command with the package name:

yarn upgrade (package-name) yarn upgrade (package-name)@(version)
yarn upgrade (package-name)@(tag)

To remove the dependency that is no longer needed in the project, run the following command:

You can use the following command to update Yarn:

Conclusion

This article taught you how to install and use Yarn on Ubuntu 22.04. By installing Yarn, you can install packages, start a new project, and share packages securely and reliably. I hope this article was useful for you and you can install Yarn easily on your Ubuntu system.

Click on a star to rate it!

Average rating 5 / 5. Vote count: 1

No votes so far! Be the first to rate this post.

Источник

Оцените статью
Adblock
detector