By default, when running build, third-party libraries are not built, and pre-built libraries are downloaded. The build scripts automatically install these in directories under /opt/yb-build. In order for the build script to write under those directories, it needs proper permissions. One way to do that is as follows:

sudo mkdir /opt/yb-build
sudo chown "$USER" /opt/yb-build

Alternatively, specify the build options --no-download-thirdparty. Note that those options may require additional, undocumented steps.