You can uninstall or removes an installed cgi-mapserver package itself from Ubuntu 16.04 LTS (Xenial Xerus) through the terminal,
$ sudo apt-get remove cgi-mapserver
If you would like to remove cgi-mapserver and it's dependent packages which are no longer needed from Ubuntu,
$ sudo apt-get remove --auto-remove cgi-mapserver
If you use with purge options to cgi-mapserver package all the configuration and dependent packages will be removed.
$ sudo apt-get purge cgi-mapserver
If you use purge options along with auto remove, will be removed everything regarding the package, It's really useful when you want to reinstall again.
$ sudo apt-get purge --auto-remove cgi-mapserver