We report the results of a search for a heavy neutral gauge boson Z' decaying into the dielectron final state using data corresponding to an integrated luminosity of 5.4 fb-1 collected by the D0 experiment at the Fermilab Tevatron Collider. No significant excess above the standard model prediction is observed in the dielectron invariant-mass spectrum. We set 95% C.L. upper limits on \sigma (ppbar -> Z') X BR(Z' -> ee) depending on the dielectron invariant mass. These cross section limits are used to determine lower mass limits for Z' bosons in a variety of models with standard model couplings and variable strength.