尝试安装 nginx 时出现 dpkg 错误

尝试安装 nginx 时出现 dpkg 错误

尝试安装 nginx:

  1. 第一的:

    sudo curl -sL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
    

    结果:

    看起来一切正常:

    > ## Run `sudo apt-get install -y nodejs` to install Node.js 16.x and npm
    > ## You may also need development tools to build native addons:
    >      sudo apt-get install gcc g++ make
    > ## To install the Yarn package manager, run:
    >      curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null
    >      echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | sudo tee
    > /etc/apt/sources.list.d/yarn.list
    >      sudo apt-get update && sudo apt-get install yarn
    
  2. 然后:

    sudo apt install -y nodejs nano nginx
    

    看起来不错,但被要求跑步apt --fix-broken install

    You might want to run 'apt --fix-broken install' to correct these.
    The following packages have unmet dependencies:
     nginx : Depends: nginx-core (< 1.18.0-6ubuntu11.1~) but it is not going to be installed or
                      nginx-full (< 1.18.0-6ubuntu11.1~) but it is not going to be installed or
                      nginx-light (< 1.18.0-6ubuntu11.1~) but it is not going to be installed or
                      nginx-extras (< 1.18.0-6ubuntu11.1~) but it is not going to be installed
             Depends: nginx-core (>= 1.18.0-6ubuntu11) but it is not going to be installed or
                      nginx-full (>= 1.18.0-6ubuntu11) but it is not going to be installed or
                      nginx-light (>= 1.18.0-6ubuntu11) but it is not going to be installed or
                      nginx-extras (>= 1.18.0-6ubuntu11) but it is not going to be installed
    E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).
    
  3. 跑步:

    apt --fix-broken install`
    

    有错误:

    dpkg: error processing archive /var/cache/apt/archives/nodejs_16.13.0-deb-1nodesource1_amd64.deb (--unpack):
     trying to overwrite '/usr/share/doc/nodejs/api/fs.html', which is also in package nodejs-doc 12.22.5~dfsg-5ubuntu1
    dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
    Errors were encountered while processing:
     /var/cache/apt/archives/nodejs_16.13.0-deb-1nodesource1_amd64.deb
    needrestart is being skipped since dpkg has failed
    E: Sub-process /usr/bin/dpkg returned an error code (1)
    

我不知道下一步该怎么做,但看起来 nginx 没有安装

答案1

你说你连做都做不到apt-get install nginx。我也遇到了这个问题,就我而言,我什至无法卸载,直到我手动删除所有现有的 nginx 实例。好像我之前(尝试)有一天安装过 nginx,但我不记得了,而且我的安装很混乱。尝试

$ whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /usr/share/nginx /usr/share/man/man8/nginx.8.gz

我所做的是强制删除所有带有的rm -rf符号链接,然后删除我发现的现有符号链接。之后,我终于能够卸载你提到的所有与 nginx 相关的软件包,并实际重新安装 nginx。

wget https://launchpad.net/ubuntu/+archive/primary/+sourcefiles/nginx/1.18.0-6ubuntu11/nginx_1.18.0.orig.tar.gz
# extract
cd nginx_1.18.0.orig/nginx-1.18.0/
./configure
make

我从源代码安装(在删除所有以前的东西之前我无法做到这一点),但它应该apt-get install nginx也可以使用。

相关内容