Uninstalled Sync Gateway, Now can't Re Install

I uninstalled couchbase sync gateway version 2.8 for some reasons. To do this, I have remove directories from /opt, /home and /lib/systemd/system. Then disabled and removed the service from systemctl. But now I am trying to install 2.8 again, but getting this error-

(Reading database ... 99189 files and directories currently installed.)
Preparing to unpack couchbase-sync-gateway-enterprise_2.8.2_x86_64.deb ...
/var/lib/dpkg/info/couchbase-sync-gateway.prerm: 5: cd: can't cd to /opt/couchbase-sync-gateway/service
dpkg: warning: old couchbase-sync-gateway package pre-removal script subprocess returned error exit status 2
dpkg: trying script from the new package instead ...
/var/lib/dpkg/tmp.ci/prerm: 5: cd: can't cd to /opt/couchbase-sync-gateway/service
dpkg: error processing archive couchbase-sync-gateway-enterprise_2.8.2_x86_64.deb (--install):
new couchbase-sync-gateway package pre-removal script subprocess returned error exit status 2
Errors were encountered while processing:
couchbase-sync-gateway-enterprise_2.8.2_x86_64.deb

Can’t find any resource to fix this problem, What to do now, any help please?

I have manually created the couchbase-sync-gateway folder inside opt and then the service folder inside couchbase-sync-gateway folder. Now tried to install again and getting this new error-

(Reading database ... 99189 files and directories currently installed.)
Preparing to unpack couchbase-sync-gateway-enterprise_2.8.2_x86_64.deb ...
/var/lib/dpkg/info/couchbase-sync-gateway.prerm: 6: /var/lib/dpkg/info/couchbase-sync-gateway.prerm: 
./sync_gateway_service_uninstall.sh: not found
dpkg: warning: old couchbase-sync-gateway package pre-removal script subprocess returned error exit status 127
dpkg: trying script from the new package instead ...
/var/lib/dpkg/tmp.ci/prerm: 6: /var/lib/dpkg/tmp.ci/prerm: ./sync_gateway_service_uninstall.sh: not found
dpkg: error processing archive couchbase-sync-gateway-enterprise_2.8.2_x86_64.deb (--install):
new couchbase-sync-gateway package pre-removal script subprocess returned error exit status 127
Errors were encountered while processing:
couchbase-sync-gateway-enterprise_2.8.2_x86_64.deb

I guess I did something wrong while uninstalling. If that is the case, then what is the right way to uninstall? Couldn’t find any proper documentation for this.

You should use the package manager to uninstall, rather than manually deleting directories.
Using dpkg -r couchbase-sync-gateway in your case would’ve been sufficient.

The system can get into a state where it still thinks the package is installed but all of the directories are gone, which can disrupt future attempts at installation, because it tries to clean up the previous non-existent installation.

Try purging the existing installed sync-gateway package first. This should allow dpkg to perform a fresh installation on the next attempt instead of trying to clean up anything pre-existing.

dpkg -P couchbase-sync-gateway
dpkg -i couchbase-sync-gateway-enterprise_2.8.2_x86_64.deb
1 Like

Yes, I found that later. As I messed up, I had to manually remove all of the package files. Then I installed again.
Following are the steps for me which helped me to get the solution (for any future devs)-

  1. Find your package in /var/lib/dpkg/info, for example using: ls -l /var/lib/dpkg/info | grep <package>
  2. Move the package folder to another location
    sudo mv /var/lib/dpkg/info/<package>.* /tmp/
  3. Run the following command:
    sudo dpkg --remove --force-remove-reinstreq <package>
1 Like