This brief tutorial is going to show students and new users how to install Yarn package manager on Ubuntu 16.04 | 18.04 and 18.10.
When you’re done, you’ll be able to easily manage npm packages via Yarn APT package repository. Since Yarn guarantees that an install that worked on one system will work exactly the same way on any other system, it’s a great way to manage npm packages.
For more about Yarn, please visit its homepage.When you’re already to install Yarn, follow the steps below:
Step 1: Add Yarn APT Repository
Before installing Yarn, you should first install its package repository. To do that you’ll first need to add the repository’s GPG key to authenticate packages being installed from there. Run the commands below to add Yarn repository’s GPG key to Ubuntu.
sudo apt update sudo apt install curl curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
Next, run the commands below to add the repository
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
That’s all you need to install Yarn.
After that, run the commands below to install Yarn
sudo apt update sudo apt install yarn
Step 2: verify Yarn is Installed
To verify if Yarn is installed, run the commands below to print out the version number of Yarn installed on your system.
The output should be something similar to the line below:
Now that you have Yarn installed on your Ubuntu system, here are some of the most common commands you’ll need.
To create a new Yarn project use the yarn init command as shown bellow:
yarn init myproject
The init script will ask you several questions. You can either answer or press to use the default values.
yarn init v1.10.1 question name (richard): 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 13.40s.
Afer that, the script the script will create a basic package.json file containing the information you provided above.
For more about using Yarn, check this page.
You may also like the post below: