In this article, we will see how to solve "sh: 1: xdg-open: not found"
error on Linux. Sometimes you might face a problem when you try to run xdg-open desktop session command in your linux system. It could show "sh: 1: xdg-open: not found"
error on the output when you try to open any file, ftp, http or https URLs. Something similar happened to me as well. While I was not expecting this error but while trying to open a file called window.js
using xdg-open
utility, I noticed "sh: 1: xdg-open: not found"
error on the output.
After checking the error for few minutes, I understood the problem. So while solving the issue, I decided to write an article about this so that it will help you folks as well. You can try to follow the solution mentioned in below section and see if it solves your problem as well.
Solved "sh: 1: xdg-open: not found" error on Linux
Also Read: How to Install iTunes on Ubuntu 20.04 LTS (Focal Fossa)
If you are running xdg-open
command on sh
shell to open a file then you might see below sh: 1: xdg-open: not found
error on the output.
$ xdg-open window.js sh: 1: xdg-open: not found
Alternatively, if you try to run xdg-open
command on bash
shell then you might see below -bash: /usr/bin/xdg-open: No such file or directory
error.
cyberithub@ubuntu:~$ xdg-open window.js -bash: /usr/bin/xdg-open: No such file or directory
While above error could happen due to multiple reasons but most of the time it is due to either xdg-utils
package either not installed or if installed then there might be some problem with the installed package. In any case, we need to install xdg-utils
package using two different method. xdg-open
is part of xdg-utils
package.
Case 1: Install xdg-utils package
Due to any reason, if you don't have xdg-utils
package installed in your system then you can use sudo apt install xdg-utils
command on Debian/Ubuntu based systems to install this package as shown below. If you using RHEL/CentOS based systems, then you need to use sudo yum install xdg-utils
or sudo dnf install xdg-utils
command.
$ sudo apt install xdg-utils [sudo] password for cyberithub: Reading package lists... Done Building dependency tree Reading state information... Done The following package was automatically installed and is no longer required: libappstream-glib8 Use 'sudo apt autoremove' to remove it. The following NEW packages will be installed: xdg-utils 0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded. Need to get 61.4 kB of archives. After this operation, 328 kB of additional disk space will be used. Get:1 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 xdg-utils all 1.1.3-2ubuntu1.20.04.2 [61.4 kB] Fetched 61.4 kB in 1s (85.6 kB/s) Selecting previously unselected package xdg-utils. (Reading database ... 199730 files and directories currently installed.) Preparing to unpack .../xdg-utils_1.1.3-2ubuntu1.20.04.2_all.deb ... Unpacking xdg-utils (1.1.3-2ubuntu1.20.04.2) ... Setting up xdg-utils (1.1.3-2ubuntu1.20.04.2) ... Processing triggers for man-db (2.9.1-1) ...
Case 2: Reinstall xdg-utils package
Most of the time, by default xdg-utils
package will be available in your system so if you are getting sh: 1: xdg-open: not found
error then you need to reinstall the package by using sudo apt install --reinstall xdg-utils
command as shown below. If you using RHEL/CentOS based systems, then you need to use sudo yum reinstall xdg-utils
or sudo dnf reinstall xdg-utils
command.
$ sudo apt install --reinstall xdg-utils
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
libappstream-glib8
Use 'sudo apt autoremove' to remove it.
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 2 not upgraded.
Need to get 61.4 kB of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 xdg-utils all 1.1.3-2ubuntu1.20.04.2 [61.4 kB]
Fetched 61.4 kB in 1s (61.7 kB/s)
(Reading database ... 199757 files and directories currently installed.)
Preparing to unpack .../xdg-utils_1.1.3-2ubuntu1.20.04.2_all.deb ...
Unpacking xdg-utils (1.1.3-2ubuntu1.20.04.2) over (1.1.3-2ubuntu1.20.04.2) ...
Setting up xdg-utils (1.1.3-2ubuntu1.20.04.2) ...
Processing triggers for man-db (2.9.1-1) ...
After installing xdg-utils
using above method, if you now try to run xdg-open window.js
command again then you will notice that this time the command will run successfully as shown below.