Score:3

error: cannot stat file '/etc/alternatives/my.cnf': Invalid argument

vi flag

When running apt upgrade on my Ubuntu 22.04.1 server I get an error that prevents all upgrades. After a few weeks of googling I'm at a loss. Does anyone else recognize the cause?

Do you want to continue? [Y/n] y
Extracting templates from packages: 100%
Preconfiguring packages ...
Setting up mariadb-common (1:10.6.12-0ubuntu0.22.04.1) ...
update-alternatives: error: cannot stat file '/etc/alternatives/my.cnf': Invalid argument
dpkg: error processing package mariadb-common (--configure):
 installed mariadb-common package post-installation script subprocess returned error 
exit status 2
Errors were encountered while processing:
 mariadb-common
E: Sub-process /usr/bin/dpkg returned an error code (1)
Score:2
jp flag

In case of mariadb-common, there is a symbolic link file named /etc/alternatives/my.cnf that the Ubuntu alternatives system use:

$ ls -l /etc/alternatives/my.cnf 
lrwxrwxrwx 1 root root 22 Mar 11 10:39 /etc/alternatives/my.cnf -> /etc/mysql/mariadb.cnf

That file should be only managed by the Ubuntu alternatives system(using the update-alternatives command) ... Handling that file otherwise will break it and render it unidentifiable/unusable by the Ubuntu alternatives system ... It appears that is what happened in your case ... Hence the error:

update-alternatives: error: cannot stat file '/etc/alternatives/my.cnf': Invalid argument

To solve this remove the existing symbolic link/file like so:

sudo rm /etc/alternatives/my.cnf

Then recreate it the right way(or in your case sudo apt upgrade will do) like so:

$ sudo dpkg-reconfigure mariadb-common
update-alternatives: using /etc/mysql/mariadb.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.