Install yarn on ubuntu 18.04
Yarn is a Javascript dependency manager that stands out for being fast, secure and reliable. It is presented to us as the most solid alternative to NPM.Like npm, Yarn provides you a way to automate the process of installing, updating, configuring and removing packages retrieved from a global registry.It is an opensouce and alternative that any other Nodejs package manager’s.
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.
Step 1: Add yarn repo
First we will login the server with root user o any other user with sudo privileges.
Then open the terminal and add below GPG key.
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
Now add Yarn repository to source list
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sample output:
root@ubuntu18:~# curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
OK
root@ubuntu18:~# 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
Step 2: Install yarn
once repository is added then update apt cache
root@ubuntu18:~# apt update
If you are currently using Nodejs and NPM, then you can install yarn using below command.
root@ubuntu18:~# apt install --no-install-recommends yarn
if you are not using any nodejs and NPM then install with following command.
root@ubuntu18:~# apt install yarn
root@ubuntu18:~# apt install yarn
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libc-client2007e libpcre2-8-0 mlock
Use 'apt autoremove' to remove them.
The following additional packages will be installed:
libc-ares2 libhttp-parser2.7.1 nodejs nodejs-doc
The following NEW packages will be installed:
libc-ares2 libhttp-parser2.7.1 nodejs nodejs-doc yarn
0 upgraded, 5 newly installed, 0 to remove and 89 not upgraded.
Need to get 6,497 kB of archives.
After this operation, 30.1 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
To verify that yarn installed successfully, run the following command
root@ubuntu18:~# yarn --version
1.21.1
To create new project use init command. you can enter the values or press Enter button to apply default values.
root@ubuntu18:~# yarn init new_project
yarn init v1.21.1
question name (root): lampblogs
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 38.57s.
To upgrade yarn to latest version run following command
curl --compressed -o- -L https://yarnpkg.com/install.sh | bash
now verify yarn version
root@ubuntu18:~# yarn --version
1.22.0