keepcalculator

06 Numbers and Powers

Compile and Install from Source with Make on a VPS

Card No. 06·44768 · Updated · Standard formula, shown below

Compiling software from source on a VPS gives you control over build options, optimizations, and versions that pre-built packages may not offer. This guide walks you through the standard ./configure && make && make install workflow, covering prerequisites, step-by-step instructions, common pitfalls, and troubleshooting.

What You’ll Need

  • A VPS with a Linux distribution (Ubuntu, Debian, CentOS, etc.) and sudo or root access.
  • Basic command-line comfort: navigating directories, editing files, and running commands.
  • Build tools: build-essential on Debian/Ubuntu, or gcc, make, and binutils on RHEL/CentOS. Also pkg-config and often wget or curl.
  • Internet access to download source tarballs.

Step-by-Step

  1. Install build dependencies. On Debian/Ubuntu: sudo apt update && sudo apt install build-essential pkg-config wget. On RHEL/CentOS: sudo yum groupinstall "Development Tools" and sudo yum install pkgconfig wget. Some packages need extra libraries; check the project’s README or INSTALL file.
  2. Download the source code. Get the tarball from the official site or GitHub. For example: wget https://example.com/package-1.2.3.tar.gz. Always verify checksums if provided.
  3. Extract the archive. tar -xzf package-1.2.3.tar.gz then cd package-1.2.3.
  4. Read the documentation. Open README, INSTALL, or configure --help to see available options and requirements.
  5. Run ./configure. This checks your system for required libraries and generates a Makefile. Customize with flags: ./configure --prefix=/usr/local --with-option. The --prefix sets installation directory; default is often /usr/local.
  6. Compile with make. Run make (or make -j$(nproc) to use all CPU cores for faster builds). This compiles the source into binaries. It may take minutes to hours.
  7. Run tests (optional but recommended). make check or make test runs the project’s test suite. Fix any failures before installing.
  8. Install with make install. sudo make install. This copies files to the prefix directory. If you used a prefix under your home, you may not need sudo.
  9. Update library cache (if needed). If you installed shared libraries to a non-standard path (e.g., /usr/local/lib), run sudo ldconfig to refresh the linker cache.
  10. Verify the installation. Run which package or package --version to confirm it works. If the binary is not in PATH, add the prefix’s bin directory to your PATH.

Common Mistakes

  • Missing dependencies: Configure fails with “No package ‘foo’ found”. Install the -dev or -devel package.
  • Using sudo with wrong prefix: If you configure with --prefix=/usr and then run make install as root, you may overwrite system files. Use a separate prefix like /usr/local or /opt.
  • Not cleaning after a failed build: After fixing errors, run make clean before recompiling to avoid stale objects.
  • Ignoring configure warnings: Some warnings indicate missing features that will be silently disabled. Read them.
  • Forgetting to run ldconfig: If the program fails to start with “cannot open shared object file”, libraries are not found.

Tips

  • Use make -j$(nproc) to speed up compilation on multi-core VPS.
  • Prefer checkinstall (Debian/Ubuntu) to create a .deb package instead of make install, making uninstallation cleaner.
  • Keep the source directory after install if you plan to uninstall or modify; make uninstall works only if the Makefile supports it.
  • Consider using stow or manually installing to /opt to keep the system clean.
  • Always read the project’s INSTALL file—some packages have specific steps.

Troubleshooting

  • Configure fails with “C compiler cannot create executables”: Install gcc and make, or check if you have enough disk space and memory.
  • Make fails with “undefined reference to…”: Usually a missing library. Look at the error message for the library name, then install its dev package. For example, libssl-dev for OpenSSL.
  • Make fails with “No rule to make target …”: You may be in the wrong directory, or the source is incomplete. Re-extract the tarball.
  • Install fails with “Permission denied”: You need sudo, or the prefix directory is not writable. Adjust permissions or use a different prefix.
  • Program not found after install: The binary is not in PATH. Add export PATH=/usr/local/bin:$PATH to your shell profile, or reinstall with a prefix that is already in PATH.
  • Program runs but says “version GLIBC_2.xx not found”: The binary was compiled on a newer glibc than the system has. Recompile on the VPS itself, or use an older version.

Frequently Asked Questions

What is the difference between make and make install?

make compiles the source into binaries in the source directory. make install copies those binaries and other files to the system directories (like /usr/local/bin).

How do I uninstall a program installed from source?

If the source directory still exists, run sudo make uninstall. If not, you may have to manually delete files listed in make install output. Using checkinstall or a package manager can simplify removal.

Can I install to my home directory without root?

Yes. Use ./configure --prefix=$HOME/.local then make install. Ensure $HOME/.local/bin is in your PATH.

Why do I get “configure: error: C compiler cannot create executables”?

This usually means gcc is not installed or is misconfigured. Install build-essential on Debian/Ubuntu or gcc and make on RHEL/CentOS.

Is it safe to compile as root?

Compiling as root is not recommended because a bug in the build script could harm the system. Use a normal user and only use sudo for make install.

How do I speed up compilation?

Use make -j$(nproc) to compile with all CPU cores. Also, close other heavy processes on the VPS.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →