There aren't any nvidia-387 packages in the default 18.04 repos. The closest match to nvidia-387 in 18.04 can be installed as follows:
sudo ubuntu-drivers autoinstall # installs nvidia-driver-390
When installing an Nvidia proprietary graphics driver, it is not necessary to uninstall the nouveau open source graphics driver. The two graphics drivers can be installed alongside each other allowing the open source graphics driver to be used as a fallback alternative in case there is a problem using the proprietary graphics driver.
autoinstall command of
ubuntu-drivers installs drivers that are appropriate for automatic installation including their dependencies.
There also isn't a package named nvidia-390 in the default Ubuntu 18.04 repositories as the results of
apt show nvidia-390 shows:
$ apt show nvidia-390
State: not a real package (virtual)
N: Can't select candidate version from package nvidia-390 as it has no candidate
N: Can't select versions from package 'nvidia-390' as it is purely virtual
N: No packages found