D2 cli 'not recognized'

After I installed DHIS2 cli via yarn I still got this error, I cannot find any way to add it to my Path env var

Hi @Ameer_Salah

Welcome to the DHIS2 community!

I see the same issue in my user account and tried many times to resolve it but because it is very complicated, needs a lot of testing because it could be for many reasons, and it is most probably an issue because of cache (which is in many files.)

The way I solved this is by creating a new user account in my profile and ensure every step in the developers guide is clear and taken properly. Prerequisites and initial setup | DHIS2 Developer Portal And I believe it works because the new user account doesn’t have ‘cache.’

If I find an actual answer I will share … hope you’ll get more assistance from the community.

Hello there, @Ameer Salah and @Gassim.

I’ve had similar problems with Windows 11 and Ubuntu 22.04.1 LTS.

The problem was caused by the fact that the path to the binary executable ‘d2’ was not in the PATH environment variable.

To resolve this, I had to first identify the location where ‘d2’ is installed.

On Windows, it is located in C:\Users\<username>\AppData\Local\Yarn\bin whereas, on Ubuntu, it is located in /.yarn/bin.
Next, I added the Directory to the PATH variable, on Ubuntu you can run the following command on your terminal

  
  echo 'export PATH="$HOME/.yarn/bin:$PATH"' >> ~/.bashrc
  source ~/.bashrc 

On Windows follow this steps
Search for ‘Edit environment variables for your account’. Click on the first result as you see in the image


Next, on the advanced tab click on the button with the name Environment variables

Select path user variable from the first list of variables and click on edit as show in the screen shot in yellow

Next Click on New button and add the directory to the bin folder which is usually C:\Users\<username>\AppData\Local\Yarn\bin. Repalce with your user name.

3 Likes

Thank you very much. This has been very helpful.

1 Like

Thank you a lot, this was very helpful

2 Likes

Am getting the same error now on Mar 27, 2024 but the solution by @redet brought magic.

3 Likes