How to install yarn js on ubuntu 18.04

Yarn js Installation on Ubuntu 18.04

Yarn is a JavaScript package manager compatible with npm that helps you automate the process of installing, updating, configuring, and removing npm packages. It was created to solve a set of problems with the npm such as speeding up the packages installation process by parallelizing operations and reducing errors related to network connectivity. The method to install Yarn JS on Ubuntu 18.04 is covered in this tutorial.

Installation

The first step is to enable the Yarn repository. Make use of the following command

root@linuxhelp1:~# curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
OK

Add the Yarn APT repository to your system’s software repository list using the Following Method

root@linuxhelp1:~# echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
deb https://dl.yarnpkg.com/debian/ stable main
Once the repository is added to the system, update the package. 
root@linuxhelp1:~# apt-get update
Get:1 https://dl.yarnpkg.com/debian stable InRelease [13.3 kB]
Hit:2 http://in.archive.ubuntu.com/ubuntu bionic InRelease                     
Hit:3 http://ppa.launchpad.net/ondrej/php/ubuntu bionic InRelease              
Hit:4 http://security.ubuntu.com/ubuntu bionic-security InRelease              
Get:5 https://dl.yarnpkg.com/debian stable/main all Packages [8,242 B]         
Hit:6 http://in.archive.ubuntu.com/ubuntu bionic-updates InRelease             
Hit:7 http://in.archive.ubuntu.com/ubuntu bionic-backports InRelease           
Get:8 https://dl.yarnpkg.com/debian stable/main i386 Packages [8,242 B]  
Get:9 https://dl.yarnpkg.com/debian stable/main amd64 Packages [8,242 B]  
Fetched 38.1 kB in 1s (35.4 kB/s)                          
Reading package lists... Done
Building dependency tree       
Reading state information... Done
656 packages can be upgraded. Run 'apt list --upgradable' to see them.

After updating the package, install Yarn by running the following command.

root@linuxhelp1:~# apt-get install yarn
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libc-ares2 libhttp-parser2.7.1 nodejs nodejs-doc
Processing triggers for man-db (2.8.2-1) ...
Setting up libc-ares2:amd64 (1.14.0-1) ...
Setting up nodejs (8.10.0~dfsg-2ubuntu0.4) ...
update-alternatives: using /usr/bin/nodejs to provide /usr/bin/js (js) in auto mode
Processing triggers for libc-bin (2.27-0ubuntu2) ...

To verify that Yarn installed successfully, run the following commands which will print the Yarn version.

root@linuxhelp1:~# yarn -version
1.12.3
To create a new Yarn project use the yarn init command as shown below.
root@linuxhelp1:~# yarn init my_yarn_project
yarn init v1.12.3
question name (root): 
question version (1.0.0): 
question description: 
question entry point (index.js): 
question repository url: 
question author: 
question license (MIT): 
question private: 
success Saved package.json
Done in 65.47s.
Once completed, the script will create a basic package.json file containing the information you provided. You can later open and edit this file.

If you want to use another package in your project, you need to add it to the project dependencies.

root@linuxhelp1:~# yarn add npm1
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
└─ npm1@1.0.0
info All dependencies
└─ npm1@1.0.0
Done in 2.54s.

With this, the method to install Yarn JS on Ubuntu 18 comes to an end.

Tag : Yarn jS Ubuntu
FAQ
Q
How to create a new Yarn project?
A
To create a New yarn project Use the following command:
#yarn init my_yarn_project
Q
Does yarn use package lock JSON?
A
When it does, yarn creates a dependency tree using npm-logical-tree from the package.json and package-lock.json in the project's root directory. ... The resulting yarn.lock will have all the exact fixed versions specified in package-lock.json . Ready to be installed and committed in your repository.
Q
What is yarn node JS?
A
The JavaScript node package manager, typically abbreviated in all lowercase as npm, is the default method for managing packages in the Node.js runtime environment.
Q
What is the difference between node and NPM?
A
Node and NodeJS are the same thing, node is just a shorter way to say Node JS. ... nvm (Node version manager) is a command line interface (CLI) to install different versions of nodejs in your machine. Whereas npm (node package manager) is a CLI for managing your node modules (e.g. Creating a package, etc).
Q
Does yarn need NPM?
A
Yarn can consume the same package.json format as npm, and can install any package from the npm registry. ... When other people start using Yarn instead of npm , the yarn.lock file will ensure that they get precisely the same dependencies as you have.