Microsoft ODBC 驱动程序未完全安装,无法卸载

Microsoft ODBC 驱动程序未完全安装,无法卸载

我已经下载了这个 Debian 软件包:

curl https://packages.microsoft.com/ubuntu/16.04/prod/pool/main/m/msodbcsql/msodbcsql_13.1.4.0-1_amd64.deb -o msodbcsql_13.1.4.0-1_amd64.deb 

然后我运行了以下命令:

sudo ACCEPT_EULA=Y dpkg -i msodbcsql_13.1.4.0-1_amd64.deb

我收到了以下消息:

Selecting previously unselected package msodbcsql.
(Reading database ... 255078 files and directories currently installed.)
Preparing to unpack msodbcsql_13.1.4.0-1_amd64.deb ...
Unpacking msodbcsql (13.1.4.0-1) ...
dpkg: dependency problems prevent configuration of msodbcsql:
 msodbcsql depends on unixodbc (>= 2.3.1); however:
  Package unixodbc is not installed.

dpkg: error processing package msodbcsql (--install):
 dependency problems - leaving unconfigured
Errors were encountered while processing:
 msodbcsql

所以我意识到我必须安装unixodbc,所以我得到了sudo apt-get install unixodbc以下输出:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies.
 unixodbc : Depends: libodbc1 (>= 2.3.1) but it is not going to be installed
            Depends: odbcinst1debian2 (>= 2.3.1) but it is not going to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

此时我开始尝试删除“半安装”包,并尝试了几种不同的方法:

得出sudo dpkg -r msodbcsql

(Reading database ... 255091 files and directories currently installed.)
Removing msodbcsql (13.1.4.0-1) ...
dpkg: error processing package msodbcsql (--remove):
 subprocess installed post-removal script returned error exit status 127
Errors were encountered while processing:
 msodbcsql

得出sudo apt-get autoremove

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED
  msodbcsql
0 to upgrade, 0 to newly install, 1 to remove and 10 not to upgrade.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] Y
(Reading database ... 255077 files and directories currently installed.)
Removing msodbcsql (13.1.4.0-1) ...
dpkg: error processing package msodbcsql (--remove):
 subprocess installed post-removal script returned error exit status 127
Errors were encountered while processing:
 msodbcsql
E: Sub-process /usr/bin/dpkg returned an error code (1)

得出sudo apt-get --purge remove && sudo apt-get autoclean

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED
  msodbcsql
0 to upgrade, 0 to newly install, 1 to remove and 10 not to upgrade.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] Y
(Reading database ... 255077 files and directories currently installed.)
Removing msodbcsql (13.1.4.0-1) ...
dpkg: error processing package msodbcsql (--remove):
 subprocess installed post-removal script returned error exit status 127
Errors were encountered while processing:
 msodbcsql
E: Sub-process /usr/bin/dpkg returned an error code (1)

得出sudo apt-get -f install

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED
  msodbcsql
0 to upgrade, 0 to newly install, 1 to remove and 10 not to upgrade.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] Y
(Reading database ... 255077 files and directories currently installed.)
Removing msodbcsql (13.1.4.0-1) ...
dpkg: error processing package msodbcsql (--remove):
 subprocess installed post-removal script returned error exit status 127
Errors were encountered while processing:
 msodbcsql
E: Sub-process /usr/bin/dpkg returned an error code (1)

我也尝试在文件系统中寻找一些通配符,sudo find / -name *msodbc*希望找到一个巨大的二进制文件并手动将其删除,但没有发现任何有趣的东西。

我有点担心这次删除,因为所有之前的尝试似乎都返回了相同的错误消息/代码,而且我没有找到删除“半安装”包或解决问题的方法。

是否有我可以查看的日志文件或我可以做其他任何事情来删除该包?

我的 Ubuntu 详细信息:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.3 LTS
Release:    16.04
Codename:   xenial
$ uname -a
Linux oe-laptop 4.10.0-37-generic #41~16.04.1-Ubuntu SMP Fri Oct 6 22:42:59 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

答案1

通常,安装软件包时dpkg -i我们会执行以下操作:

sudo apt install -f

取决于是否需要依赖项,并确保安装了所需的依赖项,但在你的情况下,你尝试删除一开始就未正确设置的包。因此使用:

sudo apt update 
sudo dpkg --configure -a

做了两件事(1):更新包管理器索引记录,(2):修复您在尝试安装和删除时导致的任何错误配置。这sudo apt update是我通常遵循的解决依赖关系问题的习惯,后一个命令可以解决问题。

答案2

您遇到的问题是 dpkg 无法解决依赖关系。此外,您似乎没有阅读或遵循收到的消息“尝试‘apt-get -f install’”,这使问题更加严重。

通常sudo apt-get -f install可以解决问题,因为 apt 会解析并安装依赖项。在你的情况下,它会解决,因为在你手动安装依赖项后,问题就解决了。

如果您遇到问题,sudo apt-get -f install则必须深入挖掘并手动解决依赖关系。

因此,当以这种方式安装 .deb 时,您将:

sudo dpkg -i foo.deb
sudo apt-get -f install #this command will install dependencies
sudo dpkg -i foo.deb

当您尝试删除由于缺少依赖项而未完全安装的软件包时,您收到错误消息,并且您通过手动安装依赖项解决了该问题。

我很高兴你解决了你的问题,但是下次,不要惊慌,请阅读消息。

将来,如果可能的话,请使用 ppa 和/或先阅读。


另请查看在 Linux 和 macOS 上安装 Microsoft ODBC Driver for SQL Server由 Microsoft 维护的页面:

sudo su 
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
exit
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install msodbcsql
# optional: for bcp and sqlcmd
sudo ACCEPT_EULA=Y apt-get install mssql-tools
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
# optional: for unixODBC development headers
sudo apt-get install unixodbc-dev

另请检查:apt-get 如何修复严重损坏的软件包进行进一步的故障排除。

相关内容