Yarn is a well-known software mainly used to handle JavaScript code. It acts as a manager, working on, managing, updating, and sharing the code that is written. This software can provide assistance in tracking any dependencies or libraries. While trying to utilize this tool in Ubuntu, you may encounter an error stating “yarn command not found“.
This article will provide you with appropriate reasoning behind this error as well as how you can resolve this error.
How to Resolve the “yarn command not found”?
There are a few different explanations that will invoke the error mentioned above. This section will shed some light on some major reasons and their solutions.
Reason 1: Missing yarn tool
The first and most common reason for any “command not found” error is that the software (yarn in this case) is missing from the system. When this happens, an error as shown below will be prompted:
Solution: Install the yarn software
The most obvious solution to the reason explained above is to install the yarn software. There exist various different methods to install yarn. Let’s check them out.
Method 1: Using cmdtest
As the error states, you can install the yarn package using the command given below:
$ sudo apt install cmdtest
Method 2: Using apt-install
The most common method to install the yarn software is to use the apt repository. Simply execute the following command into the terminal to install yarn:
$ sudo apt install yarn
Once installed, you can double-check it using this command shown:
$ yarn -version
You will be shown the version of your yarn, and the error should no longer exist.
Reason 2: Missing yarn Path on System
Another very common problem that can cause the “yarn command not found” error to occur is that Yarn is not present in your systems PATH environment variables. Due to this the system is unable to locate the yarn tool.
Solution: Set the Path Variable
The best way to fix this problem is to add the global file path of yarn to the bashrc file. For this, first, check the global path of yarn using this command:
$ yarn global bin
The next step is to copy this path and insert it into the .bashrc file. The following is the syntax of the command to add to the bash script by copy-pasting it into the bashrc file:
$ export PATH="$PATH:$HOME/itslinuxfoss/.yarn/bin"
Once the path is added, execute the bashrc file using the following command:
$ source ~/.bashrc
After doing so, the “yarn command not found” error will be resolved.
Conclusion
The “yarn command not found” error is invoked when the yarn tool is not installed on the system or its PATH environment variables are not set. To fix this, you can install the tool using “sudo apt install yarn” or “sudo apt install cmdtest” commands. Other than this, it can also be fixed by adding the PATH to the bashrc file. This article has provided an in-depth guide on the reason behind this problem as well as its solutions.
TUTORIALS ON LINUX, PROGRAMMING & TECHNOLOGY