Sccache is a command line tool that speeds up the recompilation process by caching previously compiled objects. Sccache include support for C, C++, Rust, and other languages. By caching previous compilations and reusing the results when the same inputs are encountered again, Sccache significantly reduces the time needed for subsequent builds. Sccache is similar to the Ccache command line tool. This tutorial explains how to install Sccache on Ubuntu 24.04.
Install Sccache
Get the latest release version of Sccache from its official GitHub repository:
SCCACHE_VERSION=$(curl -s "https://api.github.com/repos/mozilla/sccache/releases/latest" | grep -Po '"tag_name": "v\K[0-9.]+')
Download Sccache:
wget -qO sccache.tar.gz https://github.com/mozilla/sccache/releases/latest/download/sccache-v$SCCACHE_VERSION-x86_64-unknown-linux-musl.tar.gz
Create a temporary directory and extract the tar.gz
file contents into it:
mkdir sccache-temp
tar xf sccache.tar.gz --strip-components=1 -C sccache-temp
Move the sccache
command to the /usr/local/bin
directory:
sudo mv sccache-temp/sccache /usr/local/bin
Set execute permission:
sudo chmod a+x /usr/local/bin/sccache
The sccache
command is now available system-wide for all users. Verify its version using the following command:
sccache --version
Finally, clean up by deleting the temporary directory and the downloaded file:
rm -rf sccache.tar.gz sccache-temp
Testing Sccache
To utilize Ccache, simply prepend the compilation command with ccache
.
For demonstration purpose, create a main.cpp
file:
nano main.cpp
Add the following lines of code:
#include <iostream>
int main() {
std::cout << "Hello world" << std::endl;
return 0;
}
Compile code by prefixing the command with sccache
like this:
sccache g++ main.cpp -o test
Uninstall Sccache
To remove Sccache, simply delete its executable file:
sudo rm -rf /usr/local/bin/sccache
Leave a Comment
Cancel reply