Skip to content

Instantly share code, notes, and snippets.

@byates
Last active June 17, 2025 20:27
Show Gist options
  • Save byates/cbb356377ed4ba4988940595e4e7789c to your computer and use it in GitHub Desktop.
Save byates/cbb356377ed4ba4988940595e4e7789c to your computer and use it in GitHub Desktop.
Install GTest library in Ubuntu
#!/bin/bash -e
if [[ $(id -u $USER) = 0 ]]; then
# If we are running as root, then we don't need (and may not have) sudo
echo "Userid=$(id -u $USER)"
SUDO=
else
SUDO=sudo
fi
# https://gist.github.com/Cartexius/4c437c084d6e388288201aadf9c8cdd5
$SUDO apt install -y libgtest-dev lcov
cd /usr/src/googletest/googletest/
$SUDO cmake CMakeLists.txt
$SUDO make
$SUDO cp lib/*.a /usr/lib
$SUDO mkdir /usr/local/lib/googletest
$SUDO ln -s /usr/lib/libgtest.a /usr/local/lib/googletest/libgtest.a
$SUDO ln -s /usr/lib/libgtest_main.a /usr/local/lib/googletest/libgtest_main.a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment