Machine learning is employed to build an energy density functional for self-bound nuclear systems for the first time. By learning the kinetic energy as a functional of the nucleon density alone, a robust and accurate orbital-free density functional for nuclei is established. Self-consistent calculations that bypass the Kohn-Sham equations provide the ground-state densities, total energies, and root-mean-square radii with a high accuracy in comparison with the Kohn-Sham solutions. No existing orbital-free density functional theory comes close to this performance for nuclei. Therefore, it provides a new promising way for future developments of nuclear energy density functionals for the whole nuclear chart.