Table of Contents
Install Yarn on Ubuntu 18.04
Before you start to install Yarn on Ubuntu 18.04. You must have the non-root user account on your system with sudo privileges.
Install Yarn on Ubuntu
First you will need to add Yarn APT repository to your system. Then you will install Yarn on Ubuntu.
Now import Yarn repositories GPG key using following command to enable the Yarn repository using following curl command:
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
After importing key add Yarn APT repository using following command:
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
Update APT package manager index and install Yarn using following commands. Following command will also install Node.js when installing Yarn.
sudo apt update
sudo apt install yarn
If you don’t want to install Node.js automatically with Yarn then use following command:
sudo apt install --no-install-recommends yarn
Now confirm installation and check version of Yarn using following command:
The output should look like:
Eaxamples of Using Yarn
Create a new Project
You can create new project using Yarn running following command. This command will also ask you some questions please press
to use default values or type answer.
sudo yarn init new_project
NOTE: Now it will create
package.json file saving information provided by you. You can also edit the information inside file anytime.
The above command output should look like:
yarn init v1.13.0 question name (vagrant): Linux4one question version (1.0.0): 0.0.1 question description: Testing Yarn question entry point (index.js): question repository url: question author: Linux4one question license (MIT): question private: success Saved package.json Done in 17.56s.
Install all dependencies
To install all the dependencies given inside
package.json file use following command
The above command will install all the dependencies given in
Following is the basic syntax for adding dependency:
yarn add [package_name]
yarn add [package_name]@[version_number_or_tag_name]
The above command will add dependency to your project updating
The basic syntax for removing dependency is given below:
yarn remove [package_name]
The above command removes specific dependency from your project updating
The basic syntax for upgrading dependency is given below:
yarn upgrade [package_name]
yarn upgrade [package_name]@[version_number_or_tag_name]
The above command will upgrade specific package to latest version in your project then updates
You have successfully learned how to install Yarn on Ubuntu 18.04. If you have any queries regarding this then please don’t forget to comment below.