When running commands on sudo, sometimes it gives error - command not found

In this article
  1. Introduction
  2. The Cause
  3. The Solution


The sudo command gives superuser rights to the present user to execute any commands that follow the sudo command. For instance to run the fdisk -l superuser privileges are needed. This command cannot be run by a normal user. In order to run this command as root, one needs to prefix sudo with the command. So this command becomes: sudo fdisk -l


The Cause

In AryaLinux sometimes, Command not found error occurs when you run a command using sudo. This happens for applications that are not installed in the regular /bin, /sbin, /usr/bin, /usr/sbin, /usr/local/bin paths. For example when you install openjdk or nodejs, it gets installed in /opt. In such a situation if you were to run let's say the npm command using sudo, it would fail in AryaLinux. For example the following command would fail:

sudo npm install -g @angular/cli

The Solution

In order to make such commands work, you need to pass the -i option to sudo. So the above example would become:

sudo -i npm install -g angular/cli