How to fix error of Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead in Ubuntu Linux 22.04 LTS or Linux Mint 21

In Ubuntu 22.04 LTS or Linux Mint 21, there has been a change in the way keys to repos are stored. When installing software like Spotify from the internet via instructions there, the commands used cause an error when running apt-get update. The following error appears:

Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).

To overcome that error, open a terminal window and enter the following commands:

$ sudo apt-key list | more <enter>
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).

pub rsa4096 2021-10-27 [SC] [expires: 2023-01-20]
F9A2 1197 6ED6 62F0 0E59 361E 5E3C 45D7 B312 C643
uid [ unknown] Spotify Public Repository Signing Key tux@spotify.com

$ sudo apt-key export B312C643 | sudo gpg --dearmour -o /etc/apt/trusted.gpg.d/spotify.gpg <enter>

Note the B312 C643 needs to be combined and used in the above command. Now running sudo apt-get update will not show the key error anymore.