How do I set Ubuntu to use the primary time server time.nist.gov? [duplicate]

The previous answer is quite good but it describes the ntp package which isn't installed by default. Nowadays Ubuntu uses systemd which has a piece of code for time synchronization. You need to edit /etc/systemd/timesyncd.conf file and change the line #NTP= to NTP=time.nist.gov. After that you need to apply the changes:

$ sudo systemctl restart systemd-timesyncd

And check the status:

$ systemctl status systemd-timesyncd
    systemd[1]: Starting Network Time Synchronization...
    systemd[1]: Started Network Time Synchronization.
    systemd-timesyncd[30976]: Synchronized to time server 132.163.96.3:123 (time.nist.gov).

You can get more information by:

$ man 5 timesyncd.conf
$ man 8 systemd-timesyncd.service