A new method to solve the Dirac equation on a 3D lattice is proposed, in which the variational collapse problem is avoided by the inverse Hamiltonian method and the fermion doubling problem is avoided by performing spatial derivatives in momentum space with the help of the discrete Fourier transform, i.e., the spectral method. This method is demonstrated in solving the Dirac equation for a given spherical potential in 3D lattice space. In comparison with the results obtained by the shooting method, the differences in single particle energy are smaller than $10^{-4}$~MeV, and the densities are almost identical, which demonstrates the high accuracy of the present method. The results obtained by applying this method without any modification to solve the Dirac equations for an axial deformed, non-axial deformed, and octupole deformed potential are provided and discussed.