Find the latest version of gcc and switch to it - gcc

I installed multiple versions of gcc on a Ubuntu 16.04 and I'm wondering how to set up the system to use the latest version of gcc without uninstalling the older ones.
I'd prefer if it was a simple script and not a dependency because I'm installing it in a Docker container and I don't want to bloat it.

# list everything in /usr/bin
# leave the ones that start with gcc
# remove everything but the version numbers
# remove anything but the numbers
# sort them
# get the last one
version=$(ls /usr/bin/ | grep '^gcc' | cut -d'-' -f2 | grep -o '[0-9]\+\(\.[0-9]\+\)\?' | sort | tail -n 1)
# remove the symbolic link to the current version of gcc
rm /usr/bin/gcc
# remove the symbolic link to the current version of g++
rm /usr/bin/g++
# create symbolic links to the latest versions
ln -s /usr/bin/g++-${version} /usr/bin/g++
ln -s /usr/bin/gcc-${version} /usr/bin/gcc

Related

Finding latest version of anaconda automatically from bashrc

I'm trying to create a code which will fetch the latest version of anaconda and install it.
Currently we can do this to install the latest version:
mkdir tmp
cd tmp
wget https://repo.anaconda.com/archive/Anaconda3-2020.11-Linux-x86_64.sh
bash Anaconda3-2020.11-Linux-x86_64.sh
I want the script to be more generalized such that the code would automatically find the latest version of anaconda, download the shell script file and install it.
You can use this to get the latest version:
wget https://repo.anaconda.com/archive/ -q -O- |\
grep 'Anaconda3'| \
sed -n 's|.*>Anaconda3-\([0-9]\{4\}\.[0-9]\{2\}\)-.*|\1|p'
uniq |\
sort -r |\
head -1
This solution works only for those versions that use the year format (e.g. 2020-07), but since the latest version will presumably be of that format that should be fine.
Some explanation:
wget to fetch the contents of the archive page, which gives us the HTML content containing all the download URLs. -q quiets the output, -O- prints to stdout. Alternatively, you can use curl -s to the same effect.
grep 'Anaconda3' gives us the lines containing Anaconda, which contain the download links.
Use sed to select the version strings from the download links, e.g. 2020-11. That gives you a list of all versions (of the format YYYY-MM).
Sort that lists and select the first entry, which is the latest version.
Use the version in the rest of your script and you are done. A complete solution would be:
version=$(wget https://repo.anaconda.com/archive/ -q -O- |\
grep 'Anaconda3'|\
sed -n 's|.*>Anaconda3-\([0-9]\{4\}\.[0-9]\{2\}\)-.*|\1|p' |\
uniq |\
sort -r |\
head -1)
wget "https://repo.anaconda.com/archive/Anaconda3-$version-Linux-x86_64.sh"
I'm sure fetching the latest version could be made more efficient, but this should be sufficient for your use case.

How to install GNU grep on Mac OS?

I need to install GNU grep on my Mac but I'm finding some difficulties.
I tried doing this:
brew install grep --with-default-names
But this is no longer an option since Homebrew removed --with-default-names.
Can anyone provide a solution for this?
Yes, --with-default-names was removed.
But some formulas, like grep, provided a workaround for this:
$ brew info grep
...
==> Caveats
All commands have been installed with the prefix "g".
If you need to use these commands with their normal names, you
can add a "gnubin" directory to your PATH from your bashrc like:
PATH="/usr/local/opt/grep/libexec/gnubin:$PATH"
...
First, to install, just do install without --with-default-names.
$ brew install grep
...
==> Summary
🍺 /usr/local/Cellar/grep/3.3: 21 files, 880.7KB
You should also see that same "Caveats" info I mentioned at the start. Now, by default, the Homebrew grep would be prefixed by a "g", so it's accessible as ggrep.
$ ggrep -V
ggrep (GNU grep) 3.3
Packaged by Homebrew
Copyright (C) 2018 Free Software Foundation, Inc.
...
This prevents it from shadowing the built-in grep that comes with Mac.
$ grep -V
grep (BSD grep) 2.5.1-FreeBSD
If you really need to use grep and not ggrep, just follow the instructions and put /usr/local/opt/grep/libexec/gnubin at the start of your PATH. You have to do this in your .bashrc or .bash_profile (whichever one you use).
$ echo 'export PATH="/usr/local/opt/grep/libexec/gnubin:$PATH"' >> ~/.bash_profile
$ source ~/.bash_profile
$ grep -V
grep: warning: GREP_OPTIONS is deprecated; please use an alias or script
grep (GNU grep) 3.3
Packaged by Homebrew
...

Installing latest docker compose on Ubuntu

I use the following to install the most recent docker compose for my ubuntu server:
curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
How to do I make this more version agnostic. For instance, so that I do not have to go in and keep changing the version -which in this case is 1.21.2. How do I change the command so it gets the most latest stable release?
How do I change the command so it gets the most latest stable release?
You could try following:
curl -L https://github.com/docker/compose/releases/download/`curl -Ls -o /dev/null -w %{url_effective} https://github.com/docker/compose/releases/latest | awk -F / '{print $NF}'`/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
This is same as your script only replacing actual version (1.21.2 in your case) with latest tag over several steps:
First we get redirection url for latest stable:
curl -Ls -o /dev/null -w %{url_effective} https://github.com/docker/compose/releases/latest
currently it resolves to https://github.com/docker/compose/releases/tag/1.21.2
Then we get version tag out of redirection url:
| awk -F / '{print $NF}'
currently resolving to 1.21.2
Finally we execute it in place of version number using your original curl statement. Note that this can break if latest tag is not properly redirected and ads some extra complexity, but automates version pulling as requested.
Accepted answer isn't the latest stable version according to https://docs.docker.com/compose/release-notes/ (returns v2 instead of the latest v1 which I was looking for)
This is the monstrosity I went with
rm -Rf /usr/local/bin/docker-compose && version=$(curl -s https://docs.docker.com/compose/release-notes/ | grep "Docker Compose release notes" | grep "Estimated reading time" | sed 's/.*id=//g' | sed 's/<.*$//g' | sed 's/.*>//g') && curl -L https://github.com/docker/compose/releases/download/${version}/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose && chmod +x /usr/local/bin/docker-compose

Installing eclim on osx 10.8.5 fails - no acceptable grep found

Im trying to install eclim on OSX 10.8.5 and the installer fails because it does not like the grep I have installed.
[ANT][exec]configure: error: no acceptable grep could be found
[ANT][exec] checking for grep that handles long lines and -e...
My grep has -e
SYNOPSIS
grep [OPTIONS] PATTERN [FILE...]
grep [OPTIONS] [-e PATTERN | -f FILE] [FILE...]
What is going on here?
I ended up fixing this by using macports to install gcc grep. Apparently OSX now uses bsd grep by default and there are differences between the two that gcc was choking on. The part of this that a little ridiculous is that I installed gcc through XCode.

Installing readline 6.0 on OS X

I'm trying to install readline 6 from source but run into an error during 'make install'.
Here is the end of the output after executing 'sudo make install'
( cd shlib ; make DESTDIR= install )
/bin/sh ../support/mkdirs /usr/local/lib
/bin/sh ../support/shlib-install -O darwin9.7.0 -d /usr/local/lib -b /usr/local/bin -i "/usr/bin/install -c -m 644" libhistory.6.0.dylib
/bin/sh ../support/shlib-install -O darwin9.7.0 -d /usr/local/lib -b /usr/local/bin -i "/usr/bin/install -c -m 644" libreadline.6.0.dylib
install: you may need to run ldconfig
I know that ldconfig isn't installed by default on OS X, and I read somewhere that it shouldn't be needed to fix this issue. I believe it has something to do with dynamic libraries, but I haven't been able to find out how to fix the issue, anyone have any insight?
FYI, I'm running OS X on an intel 2.4ghz macbook
thanks
P.S. I also applied the 3 available readline 6 patches before running configure and make
Actually, this isn't an error at all... it's just a notice message at the end of the install. It get this too, and my readline 6 is happily installed.
If you check /usr/local/lib and see readline there, you're done :-) No need to run any equivalent of ldconfig.
$ ls /usr/local/lib | grep readline
libreadline.6.0.dylib
libreadline.6.dylib
libreadline.a
libreadline.dylib

Resources