I was removing a desktop entry for an application earlier today, and then by mistake, I removed the /usr/share/applications folder completely instead of the desktop entry. The applications still worked when launched from the terminal, but when the next time I turned on my Fedora machine, I could not even access the GDM login screen. Now, how do you fix this?
You can do one of the following things :
- Either download a full ISO of your operating system from their official website and load it up into a thumb drive using Ventoy and then copy the /usr/share/applications from the ISO to your system.
- You can also just reinstall all the applications, which is relatively easy compared to the first method.
Now, the first method is straightforward, so I’m going to discuss the second method in this tutorial.
Open the TTY
If you’re already in a logged-in system, then you can directly proceed to the installation step of this tutorial. If not, then while logging in, you have to open a TTY (short for TeleTYpewriter) by pressing Ctrl + Alt + F2 keys one after the other.
Log in and write a bash script
Now, type your username in the terminal and then your password and log in. To simplify the installation process, we will create a bash script that will contain all the information containing all the names of the packages we have already installed on your distribution. Create a bash file using your preferred text editor, such as vim or nano.
vim fedora.sh # or for the nano editor users : nano fedora.sh
Now, press ‘I’ key to get in the insert mode if you are using vim editor and if you are using nano then directly start writing the following script :
Now save the file by pressing the escape key and then typing :wq if you are using vim and if you’re using nano, then press Ctrl + O and Ctrl + X to save and exit. Now, we have to create another text file that will contain all the package’s names, and then we will just append it at the end of our first script. Again, type the following to create that text file :
rpm -qa | sort > ~/pkgs.txt
You can open the text file and verify that these are the files you want to not install, but I will not recommend this unless you know what you are doing. Now time to append the package names into our script, type:
cat pkgs.txt >> fedora.sh
Now, again open the script using your preferred editor and add the following lines at the end of your script (If you’re using vim then press Shift + g to get to the bottom of the file). Note that there is a double quote to close the list:
" sudo dnf reinstall $pkgs
Now, save and exit again, and then make the script executable by typing :
sudo chmod +x fedora.sh
Create the /usr/share/applications directory
Before we execute the script, let’s manually create this directory so that we do not encounter any errors. Type the following :
sudo mkdir /usr/share/applications
Make sure that you are connected to the Internet
Now, make sure that you are connected to the internet, either by Ethernet port or via Wi-Fi. If you’re not sure about connecting to the internet using Wi-Fi, then type the following command :
# To check the connection status nmcli dev status # To scan all the available devices nmcli dev wifi list # To connect to a device, type : nmcli --ask dev wifi connect SSID
Execute the script
The script execution is really easy, just type the following in your terminal :
Now sit back and relax for a while, the download, and installation process will take time depending upon your Internet speed, the number of packages installed, and your hardware speed. Reboot your system when all this process is complete, and you will be greeted by the GDM login manager.
This method is not perfect, so if you still cannot access some applications, then you can manually reinstall them using the following command :
sudo dnf reinstall <package name>