The way sudo
works is that by default it gives you 15 minutes before it will ask for password again. So yes, using the two commands, will work perfectly fine, and depending on how long apt-get update
runs you will need to enter password once.
However, this is not the best practice. Instead, I would suggest making your whole script run with sudo instead of placing it in front of each command in file. In other words, the script should be:
#!/bin/bash
apt-get update
apt-get upgrade
And run it as
sudo ./my_script.sh
Notice that here we're using #!/bin/bash
line to use bash
shell as interpreter. This is very different from /bin/sh
. For what you're doing it makes no difference, but if you need to be aware that they differ in syntax of some of the operators.
However, even better approach would be to get rid of script altogether and use function or alias that does what you want. Scripts are really for large amounts of code that you want to reuse. For 2 - 3 lines a function or alias in ~/.bashrc
file that's going to be sufficient.
Personally I'd make something like this in my ~/.bashrc
alias agu="sudo bash -c 'apt-get update && apt-get upgrade'"
Let's look at the available packages in the Ubuntu repositories for libstdc++6
:
$ rmadison libstdc++6 // The rmadison command is provided by the 'devscripts' package
libstdc++6 | 4.6.3-1ubuntu5 | precise | amd64, armel, armhf, i386, powerpc
libstdc++6 | 4.8.2-19ubuntu1 | trusty | amd64, arm64, armhf, i386, powerpc, ppc64el
libstdc++6 | 4.8.4-2ubuntu1~14.04.4 | trusty-security | amd64, arm64, armhf, i386, powerpc, ppc64el
libstdc++6 | 4.8.4-2ubuntu1~14.04.4 | trusty-updates | amd64, arm64, armhf, i386, powerpc, ppc64el
libstdc++6 | 5.3.1-14ubuntu2 | xenial | amd64, arm64, armhf, i386, powerpc, ppc64el, s390x
libstdc++6 | 5.4.0-6ubuntu1~16.04.10 | xenial-security | amd64, arm64, armhf, i386, powerpc, ppc64el, s390x
libstdc++6 | 5.4.0-6ubuntu1~16.04.11 | xenial-proposed | amd64, arm64, armhf, i386, powerpc, ppc64el, s390x
libstdc++6 | 5.4.0-6ubuntu1~16.04.11 | xenial-updates | amd64, arm64, armhf, i386, powerpc, ppc64el, s390x
libstdc++6 | 8-20180414-1ubuntu2 | bionic | amd64, arm64, armhf, i386, ppc64el, s390x
libstdc++6 | 8.2.0-1ubuntu2~18.04 | bionic-updates | amd64, arm64, armhf, i386, ppc64el, s390x
libstdc++6 | 8.2.0-7ubuntu1 | cosmic | amd64, arm64, armhf, i386, ppc64el, s390x
libstdc++6 | 8.2.0-12ubuntu1 | disco | amd64, arm64, armhf, i386, ppc64el, s390x
libstdc++6 | 8.2.0-13ubuntu1 | disco-proposed | amd64, arm64, armhf, i386, ppc64el, s390x
Aha. Neither of your two options, 8.1.0-5ubuntu1~14.04 nor 8.2.0-9 is from the Ubuntu repositories.
Now we know the problem: You have unwisely added non-Ubuntu sources that are providing packages that are incompatible with your release of Ubuntu. This is also called a 'version conflict' or 'held broken packages'. They are not really "broken", just wrong version...but they do break your system.
The solution is to uninstall ALL packages from that unwise source, and then to delete that source. Return your system to using packages provided by the Ubuntu repositories. Then MySQL will install.
If you don't know how to uninstall packages from a specific source, then see How can PPAs be removed? for instructions on how to install and use the ppa-purge
command.
Best Answer
On all currently supported versions of Ubuntu, we can use
apt
instead ofapt-get
. If you want to capture the output in a file, useapt-get
, but otherwise useapt
as its output is more readable (and who likes typing?).Downloads information from the repositories 1 APT is configured to check, and updates the
dpkg
database of available, installed, and uninstalled packages to reflect changes in the repositories. This means that when you query the database on your system with commands likethey will print accurate information, and when you run commands like
they will fetch the latest available version.
When you run
sudo apt update
you may see that some packages are upgradable, meaning new versions have been added to the repositories. Newer versions often have bug fixes and security updates, so you should install them. This can be done by upgrading all packages that have new versions available with the commandIf the kernel was upgraded (packages like
linux-image-4.15.0-20-generic
) you should then run a command to remove old kernel versions (except for the second-newest which is kept as a spare, in case the new one is buggy). You can use this command:to do that. This command also removed orphaned packages. These generally only exist when you use a command like
and
package-name
has dependencies that were installed along with it automatically, but are not needed by any other package.For
autoclean
, I refer you toman apt-get
The other three commands are really important and should generally be run regularly to keep the system secure and updated and avoid filling the disk with old kernel files, but you probably won't see much difference after running
autoclean
. The few files it might delete occasionally are unlikely to amount to much.1These repositories are configured by default, so you usually don't need to do anything with them. They are listed in the file
/etc/apt/sources.list
and in files in/etc/apt/sources.list.d
. APT is strict about the format of these files (for security reasons) and will throw errors if they have bad syntax. If your system has a graphical environment, it will have an option to configure repositories in settings. You need root privilege to do that job.