How to change rpmbuild (_tmppath) in a spec file (rpmbuild ignored directory) Linux

Below article explains in detail

Step by Step Guide to build an rpm from scratch by building a source archive using Red Hat Linux

By default when we attempt to build an rpm, the rpmbuild command will look for the below directories under /root/ or the user home folder

drwxr-xr-x 4 root root  46 May 13 00:55 BUILD
drwxr-xr-x 2 root root   6 May 13 00:55 BUILDROOT
drwxr-xr-x 3 root root  20 May 12 21:07 RPMS
drwxr-xr-x 3 root root  84 May 13 00:32 SOURCES
drwxr-xr-x 2 root root  25 May 13 01:36 SPECS
drwxr-xr-x 2 root root 100 May 13 00:55 SRPMS

But if you have created these under some other path then rpmbuild will most likely fail with below error message

# rpmbuild -ba deepak.spec
error: File /root/rpmbuild/SOURCES/deepak-1.0.0-1.tar.gz: No such file or directory

which mean rpmbuild is looking at the wrong place for the source file

Solution:

To change the location of the sourcepath modify or create a new rpmmacros in the user home folder as shown below

Here I have changed my rpmbuild path

# vim /root/.rpmmacros
%_topdir /tmp/rpmbuild
%_tmppath %{_topdir}/tmp

Save and exit and re-attempt to build the rpm

I hope the article was useful.