Is it fine to remove the /opt/gitlab/ directory manually after removing the gitlab package from the system?

That directory is populated with gitlab-ce reconfigure command after installation and holds variable data, configurations related to gitlab-ce package.

The recommended process to uninstall it was

  1. Remove services

     sudo gitlab-ctl uninstall
    
  2. Clean any data generated by usage of the package

     sudo gitlab-ctl cleanse
    
  3. You may also want to remove any accounts you configured. To do so

     sudo gitlab-ctl remove-accounts
    
  4. Then remove the package using

     sudo dpkg -P gitlab-ce
    

Furthermore, gitlab-ce uses these directories (as described here)

  • /opt/gitlab holds application code for GitLab and its dependencies.
  • /var/opt/gitlab holds application data and configuration files that gitlab-ctl reconfigure writes to.
  • /etc/gitlab holds configuration files for omnibus-gitlab. These are the only files that you should ever have to edit manually.
  • /var/log/gitlab contains all log data generated by components of omnibus-gitlab.

So, First remove the package recommended way (Even if you need to reinstall it). You can then remove those data using rm safely.

Information found from omnibus-gitlab README page


Should I delete these directory manually or not?

Filesystem Hierarchy Standard for /opt/:

No other package files may exist outside the /opt, /var/opt, and /etc/opt hierarchies except for those package files that must reside in specific locations within the filesystem tree in order to function properly. For example, device lock files must be placed in /var/lock and devices must be located in /dev.

Anything in /opt/ is maintained by an uninstall-script that basically does a shutdown of the service (if needed) and a bunch of rm's. So if you want to do that manually you need to shutdown the service (if needed) and then rm it.

Mind that /opt/ has a companion /etc/opt/ that might contain files related to that package.