侧边栏壁纸
  • 累计撰写 402 篇文章
  • 累计创建 63 个标签
  • 累计收到 122 条评论

目 录CONTENT

文章目录

Ubuntu 更新Jenkins到最新2.361.4版

Z同学
2022-11-28 / 0 评论 / 1 点赞 / 134 阅读 / 3,611 字
温馨提示:
本文最后更新于 2022-11-28,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

1. 介绍

当我们通过Unbuntu 下载安装完毕Jenkins之后,在后面的时间中如果官方发布了最新的Jenkins。

我们如果想升级,这里就来介绍一下ubuntu系统下的软件更新。

请注意了,从Jenkins 2.346.3版本开始,就必须依赖JDK 11才行了。JDK 8 已经不支持了。

请注意:主要是通过apt-get命令进行手动安装的软件。

如果不了解如何通过ubuntu 手动安装Jenkins,可以参考我的文章:WSL2 Ubuntu 20.04 LTS 环境下安装Jenkins (zinyan.com) 来进行了解。

image-20221128194848600

2. 更新

更新其实比较简单,如果我们的ubuntu还有其他的软件需要更新的话,可以通过命令一起进行更新。

2.1 更新apt源

首先第一步,进行apt-get 配置更新:apt-get update

在这里需要注意一下,如果我们的登录用户权限不足,直接使用上面的命令会出现类似下面的错误:

zinyan@LAPTOP-141OG4MA:~$ apt-get update
Reading package lists... Done
E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/
W: Problem unlinking the file /var/cache/apt/pkgcache.bin - RemoveCaches (13: Permission denied)
W: Problem unlinking the file /var/cache/apt/srcpkgcache.bin - RemoveCaches (13: Permission denied)

主要错误就是:Permission denied (权限被拒绝)。因为这个更新操作是属于管理员角色才有的权限。

当我们改为 sudo apt-get update 就可以了。

PS: 输入sudo 后可能会让你输入root用户的密码才能进行下一步操作,示例如下:

zinyan@LAPTOP-141OG4MA:~$ sudo apt-get update
[sudo] password for zinyan:

执行update 之后的效果如下所示:

zinyan@LAPTOP-141OG4MA:~$ sudo apt-get update
Hit:1 http://mirrors.aliyun.com/ubuntu bionic InRelease
Get:2 http://mirrors.aliyun.com/ubuntu bionic-security InRelease [88.7 kB]
...
Get:12 https://pkg.jenkins.io/debian-stable binary/ Release [2044 B]
Get:13 http://mirrors.aliyun.com/ubuntu bionic-security/main Translation-en [428 kB]
Get:14 https://pkg.jenkins.io/debian-stable binary/ Release.gpg [833 B]
Get:15 http://mirrors.aliyun.com/ubuntu bionic-security/restricted amd64 Packages [983 kB]
Get:16 http://mirrors.aliyun.com/ubuntu bionic-security/restricted Translation-en [136 kB]
Get:17 http://mirrors.aliyun.com/ubuntu bionic-security/universe amd64 Packages [1246 kB]
Get:18 http://mirrors.aliyun.com/ubuntu bionic-security/universe Translation-en [288 kB]
Get:19 http://mirrors.aliyun.com/ubuntu bionic-security/multiverse amd64 Packages [19.0 kB]
Get:20 http://mirrors.aliyun.com/ubuntu bionic-updates/multiverse Sources [17.2 kB]
Get:21 http://mirrors.aliyun.com/ubuntu bionic-updates/main Sources [536 kB]
Get:22 http://mirrors.aliyun.com/ubuntu bionic-updates/restricted Sources [31.8 kB]
Get:23 http://mirrors.aliyun.com/ubuntu bionic-updates/universe Sources [486 kB]
Get:24 http://mirrors.aliyun.com/ubuntu bionic-updates/main amd64 Packages [2809 kB]
Get:25 https://pkg.jenkins.io/debian-stable binary/ Packages [23.6 kB]
Get:26 http://mirrors.aliyun.com/ubuntu bionic-updates/main Translation-en [517 kB]
Get:27 http://mirrors.aliyun.com/ubuntu bionic-updates/restricted amd64 Packages [1015 kB]
Get:28 http://mirrors.aliyun.com/ubuntu bionic-updates/restricted Translation-en [141 kB]
...
Fetched 15.1 MB in 5s (3212 kB/s)
Reading package lists... Done

其实只是将我们本地的apt-get中的记录进行了同步。同步了各大源站中的最新记录。

然后系统才能比较我们本地安装的和最新版本有没有区别了。如果有区别就是需要安装更新的。

PS: 从更新源中就可以看到Get:14 https://pkg.jenkins.io/debian-stable binary/ Release.gpg [833 B] 这个代表更新了jenkins的源。

2.2 使用 upgrade 全部更新

我们如果有多个软件需要一起更新可以通过upgrade命令进行全部更新。示例如下:

zinyan@LAPTOP-141OG4MA:~$ sudo apt-get upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages have been kept back:
  libgl1-mesa-dri libglapi-mesa libglx-mesa0 mesa-vulkan-drivers sosreport ubuntu-advantage-tools
The following packages will be upgraded:
  ca-certificates cloud-init jenkins libcups2 libjbig0 libjpeg-turbo8 libksba8 libnss3 libpixman-1-0
  libpython2.7-minimal libpython2.7-stdlib libtiff5 multiarch-support open-vm-tools openjdk-8-jdk
  openjdk-8-jdk-headless openjdk-8-jre openjdk-8-jre-headless python2.7 python2.7-minimal snapd tzdata unzip
23 upgraded, 0 newly installed, 0 to remove and 6 not upgraded.
Need to get 179 MB of archives.
After this operation, 25.1 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

从上面的数据结果中我们需要关注的是:The following packages will be upgraded:(将升级以下程序包)内容下面的模块,

例如我上面有 ca-certificatescloud-initjenkinslibcups2libjbig0libjpeg-turbo8libksba8libnss3libpixman-1-0
libpython2.7-minimallibpython2.7-stdliblibtiff5multiarch-supportopen-vm-toolsopenjdk-8-jdk
openjdk-8-jdk-headlessopenjdk-8-jreopenjdk-8-jre-headlesspython2.7python2.7-minimalsnapdtzdataunzip

等软件的更新,23 upgraded, 0 newly installed, 0 to remove and 6 not upgraded.(23个已升级,0个新安装,0个要删除,6个未升级。)

23个就是我们要进行更新操作的,6个未升级的是The following packages have been kept back 下面的内容。

然后就是介绍,下载更新包需要179MB的存储,然后安装完毕后,会占用25.1MB的磁盘存储空间。

当我们输入y 并按回车之后,将会进入自动更新操作:

...
Setting up openjdk-8-jre-headless:amd64 (8u352-ga-1~18.04) ...
Installing new version of config file /etc/java-8-openjdk/accessibility.properties ...
Installing new version of config file /etc/java-8-openjdk/security/java.policy ...
Installing new version of config file /etc/java-8-openjdk/security/java.security ...
Setting up python2.7 (2.7.17-1~18.04ubuntu1.8) ...
Setting up openjdk-8-jre:amd64 (8u352-ga-1~18.04) ...
Setting up openjdk-8-jdk-headless:amd64 (8u352-ga-1~18.04) ...
Setting up openjdk-8-jdk:amd64 (8u352-ga-1~18.04) ...
Processing triggers for hicolor-icon-theme (0.17-2) ...
Processing triggers for libc-bin (2.31-0ubuntu9) ...
/sbin/ldconfig.real: /usr/lib/wsl/lib/libcuda.so.1 is not a symbolic link

Processing triggers for rsyslog (8.2001.0-1ubuntu1) ...
invoke-rc.d: could not determine current runlevel
Processing triggers for systemd (245.4-4ubuntu3) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for dbus (1.12.16-2ubuntu2) ...
Processing triggers for mime-support (3.64ubuntu1) ...
Processing triggers for ca-certificates (20211016~18.04.1) ...
Updating certificates in /etc/ssl/certs...
0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.

直到最终输出为done就代表更新完毕了。

我们如果再次使用upgrade就会看到没有更新:

zinyan@LAPTOP-141OG4MA:~$ sudo apt-get upgrade
[sudo] password for zinyan:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages have been kept back:
  libgl1-mesa-dri libglapi-mesa libglx-mesa0 mesa-vulkan-drivers sosreport ubuntu-advantage-tools
0 upgraded, 0 newly installed, 0 to remove and 6 not upgraded.

2.3 单独更新Jenkins

我们如果不想更新那么多其他的软件,而只是想更新Jenkins,那么也简单,使用only选项:

zinyan@LAPTOP-141OG4MA:~$ sudo apt-get --only-upgrade install jenkins

就会进行更新操作了,请注意更新前也需要使用apt-get update 刷新一下apt源数据之后再使用上面的更新哦。

我们如果更新完毕后使用上面的命令 就会得到下面的内容:

Reading package lists... Done
Building dependency tree
Reading state information... Done
jenkins is already the newest version (2.361.4).
0 upgraded, 0 newly installed, 0 to remove and 6 not upgraded.

我的Jenkins 已经更新到最新的2.361.4版本了。

3. 重启Jenkins

更新完毕后,我们的前端页面刷新时还是会提醒让我们进行jenkins 更新。

那是因为我们更新完毕后没有进行jenkins重启,重启之后版本才会变化。重启命令为:

zinyan@LAPTOP-141OG4MA:~$ sudo systemctl restart jenkins

你如果是通过WSL进行安装的ubuntu那么这个命令会报错,我们需要使用:

zinyan@LAPTOP-141OG4MA:~$ sudo /etc/init.d/jenkins restart
    
 * Restarting Jenkins Automation Server jenkins
Correct java version found
Correct java version found
Setting up max open files limit to 8192
zinyan@LAPTOP-141OG4MA:~$

我们如果jdk错误,或重启过程中有错误都会提示启动失败的。

4. JDK版本问题

如果重启的时候出现下面的错误:

 * Restarting Jenkins Automation Server jenkins                                                               Found an incorrect Java version
Java version found:
openjdk version "1.8.0_352"
OpenJDK Runtime Environment (build 1.8.0_352-8u352-ga-1~18.04-b08)
OpenJDK 64-Bit Server VM (build 25.352-b08, mixed mode)
Aborting
Found an incorrect Java version
Java version found:
openjdk version "1.8.0_352"
OpenJDK Runtime Environment (build 1.8.0_352-8u352-ga-1~18.04-b08)
OpenJDK 64-Bit Server VM (build 25.352-b08, mixed mode)
Aborting

根据Jenkins的更新资料网站:LTS Changelog (jenkins.io)

从Jenkins 2.346.3版本开始jdk版本必须是11才行了。

image-20221128202553765

所以,我们需要更新自己的本地安装的jdk,从jdk 1.8 升级到jdk 11。

更新JDK 的方式如下:

4.1 卸载jdk 1.8

如果你不想同时安装jdk 1.8 和jdk 11 那么可以卸载掉jdk 1.8 当然两个一起安装也是支持的。

这里介绍如何进行卸载,关键命令为:sudo apt-get remove openjdk-8-jdkapt-get remove openjdk--8-jre-headless。示例如下:

zinyan@LAPTOP-141OG4MA:~$ sudo apt-get remove openjdk-8-jdk
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  adwaita-icon-theme at-spi2-core ca-certificates-java fontconfig fonts-dejavu-extra gtk-update-icon-cache
  hicolor-icon-theme humanity-icon-theme java-common libatk-bridge2.0-0 libatk-wrapper-java libatk-wrapper-java-jni
  libatk1.0-0 libatk1.0-data libatspi2.0-0 libavahi-client3 libavahi-common-data libavahi-common3 libcairo2 libcups2
  libdatrie1 libgail-common libgail18 libgdk-pixbuf2.0-0 libgdk-pixbuf2.0-bin libgdk-pixbuf2.0-common libgif7
  libgraphite2-3 libgtk2.0-0 libgtk2.0-bin libgtk2.0-common libharfbuzz0b libjbig0 libjpeg-turbo8 libjpeg8 liblcms2-2
  libnspr4 libnss3 libpango-1.0-0 libpangocairo-1.0-0 libpangoft2-1.0-0 libpcsclite1 libpixman-1-0 librsvg2-2
  librsvg2-common libthai-data libthai0 libtiff5 libxcb-render0 libxcb-shm0 libxcursor1 multiarch-support
  openjdk-8-jdk-headless openjdk-8-jre openjdk-8-jre-headless ubuntu-mono
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  openjdk-8-jdk
0 upgraded, 0 newly installed, 1 to remove and 6 not upgraded.
After this operation, 4329 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 107716 files and directories currently installed.)
Removing openjdk-8-jdk:amd64 (8u352-ga-1~18.04) ...

可以看到 The following packages will be REMOVED:(将删除以下安装包) openjdk-8-jdk 当我们输入y之后就会进行卸载操作了。

卸载完毕后的输出内容为:Removing openjdk-8-jdk:amd64 (8u352-ga-1~18.04) …(正在删除openjdk-8-jdk:amd64(8u352-ga-1~18.04)。。。)

当jdk卸载完毕后,我们还有headless需要进行卸载,执行第二个命令 sudo apt-get remove openjdk-8-jre-headless 示例如下:

zinyan@LAPTOP-141OG4MA:~$ sudo apt-get remove openjdk-8-jre-headless
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  adwaita-icon-theme at-spi2-core fontconfig fonts-dejavu-extra gtk-update-icon-cache hicolor-icon-theme
  humanity-icon-theme java-common libatk-bridge2.0-0 libatk-wrapper-java libatk-wrapper-java-jni libatk1.0-0
  libatk1.0-data libatspi2.0-0 libavahi-client3 libavahi-common-data libavahi-common3 libcairo2 libcups2 libdatrie1
  libgail-common libgail18 libgdk-pixbuf2.0-0 libgdk-pixbuf2.0-bin libgdk-pixbuf2.0-common libgif7 libgraphite2-3
  libgtk2.0-0 libgtk2.0-bin libgtk2.0-common libharfbuzz0b libjbig0 libjpeg-turbo8 libjpeg8 liblcms2-2 libnspr4
  libnss3 libpango-1.0-0 libpangocairo-1.0-0 libpangoft2-1.0-0 libpcsclite1 libpixman-1-0 librsvg2-2 librsvg2-common
  libthai-data libthai0 libtiff5 libxcb-render0 libxcb-shm0 libxcursor1 multiarch-support ubuntu-mono
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  ca-certificates-java openjdk-8-jdk-headless openjdk-8-jre openjdk-8-jre-headless
0 upgraded, 0 newly installed, 4 to remove and 6 not upgraded.
After this operation, 144 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 107698 files and directories currently installed.)
Removing openjdk-8-jre:amd64 (8u352-ga-1~18.04) ...
Removing openjdk-8-jdk-headless:amd64 (8u352-ga-1~18.04) ...
Removing openjdk-8-jre-headless:amd64 (8u352-ga-1~18.04) ...
Removing ca-certificates-java (20180516ubuntu1~18.04.1) ...
Processing triggers for hicolor-icon-theme (0.17-2) ...
Processing triggers for libc-bin (2.31-0ubuntu9) ...
/sbin/ldconfig.real: /usr/lib/wsl/lib/libcuda.so.1 is not a symbolic link

Processing triggers for ca-certificates (20211016~18.04.1) ...
Updating certificates in /etc/ssl/certs...
0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...

updates of cacerts keystore disabled.
done.

会同时卸载ca-certificates-java openjdk-8-jdk-headless openjdk-8-jre openjdk-8-jre-headless 这四个安装包。卸载完毕后输出:done代表操作结束了。

4.2 安装jdk 11

我们本地没有安装jdk 当我们输出java -v 的时候ubuntu会提示安装。示例如下:

zinyan@LAPTOP-141OG4MA:~$ java -v

Command 'java' not found, but can be installed with:

sudo apt install openjdk-11-jre-headless  # version 11.0.13+8-0ubuntu1~20.04, or
sudo apt install default-jre              # version 2:1.11-72
sudo apt install openjdk-16-jre-headless  # version 16.0.1+9-1~20.04
sudo apt install openjdk-17-jre-headless  # version 17.0.1+12-1~20.04
sudo apt install openjdk-8-jre-headless   # version 8u312-b07-0ubuntu1~20.04
sudo apt install openjdk-13-jre-headless  # version 13.0.7+5-0ubuntu1~20.04

zinyan@LAPTOP-141OG4MA:~$

因为没有找到java ,所以推荐以下的安装操作。

PS:我的apt源地址切换到了阿里云的镜像,所以查询和下载的速度都比较快。如果不知道如何切换,可以参考我的内容:Ubuntu apt下载源改为阿里云镜像 (zinyan.com) 查询了解。

所以我们可以直接执行:sudo apt install openjdk-11-jre-headless 进行jdk 11的安装。示例如下:

zinyan@LAPTOP-141OG4MA:~$ sudo apt-cache search jdk-11
default-jdk - Standard Java or Java compatible Development Kit
default-jdk-doc - Standard Java or Java compatible Development Kit (documentation)
default-jdk-headless - Standard Java or Java compatible Development Kit (headless)
  ca-certificates-java openjdk-11-jre-headless
0 upgraded, 2 newly installed, 0 to remove and 6 not upgraded.
Need to get 37.3 MB/37.3 MB of archives.
After this operation, 171 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirrors.aliyun.com/ubuntu bionic-security/main amd64 openjdk-11-jre-headless amd64 11.0.17+8-1ubuntu2~18.04 [37.3 MB]
Fetched 37.3 MB in 4s (8694 kB/s)
Selecting previously unselected package openjdk-11-jre-headless:amd64.
(Reading database ... 107340 files and directories currently installed.)
Preparing to unpack .../openjdk-11-jre-headless_11.0.17+8-1ubuntu2~18.04_amd64.deb ...
Unpacking openjdk-11-jre-headless:amd64 (11.0.17+8-1ubuntu2~18.04) ...
Selecting previously unselected package ca-certificates-java.
Preparing to unpack .../ca-certificates-java_20180516ubuntu1~18.04.1_all
...
done.

直到最后的done.输出就代表安装完毕了,这个时候我们通过java -version命令,就会显示本机安装的jdk的版本了。示例如下:

zinyan@LAPTOP-141OG4MA:~$ java -version
openjdk version "11.0.17" 2022-10-18
OpenJDK Runtime Environment (build 11.0.17+8-post-Ubuntu-1ubuntu218.04)
OpenJDK 64-Bit Server VM (build 11.0.17+8-post-Ubuntu-1ubuntu218.04, mixed mode, sharing)
zinyan@LAPTOP-141OG4MA:~$

就可以看到我们的系统中安装的java 已经是openjdk 11了

现在我们再重启jenkins就可以正常启动了。

5. 其他

如果其他基本环境不知道如何安装搭建可以参考文章:

Windows 11 子系统Ubuntu 中安装编译环境,安装jdk,ndk,git,make,android SDK等环境 (zinyan.com)

Ubuntu apt下载源改为阿里云镜像 (zinyan.com)

等信息。如果觉得本文更新的内容还可以,希望能够给我点个赞鼓励一下博主。谢谢。

1

评论区