1. 配置Yum源
RHEL系統安裝完成之后,如果沒有注冊並購買紅帽服務是無法連接到官方的Yum源的,也就無法直接使用Yum命令來安裝軟件包及更新系統。
[root@wuhan2020 /]# hostnamectl Static hostname: wuhan2020 Icon name: computer-laptop Chassis: laptop Machine ID: 601eca308ef84823a9e0a775d944fa23 Boot ID: 2b616f1426814536b6cd7a469718f588 Operating System: Red Hat Enterprise Linux 8.1 (Ootpa) CPE OS Name: cpe:/o:redhat:enterprise_linux:8.1:GA Kernel: Linux 4.18.0-147.el8.x86_64 Architecture: x86-64 [root@wuhan2020 /]# yum install thefuck Updating Subscription Management repositories. Unable to read consumer identity This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. Error: There are no enabled repositories in "/etc/yum.repos.d", "/etc/yum/repos.d", "/etc/distro.repos.d". [root@wuhan2020 /]# [root@wuhan2020 /]# yum update Updating Subscription Management repositories. Unable to read consumer identity This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. Error: There are no enabled repositories in "/etc/yum.repos.d", "/etc/yum/repos.d", "/etc/distro.repos.d". [root@wuhan2020 /]#
但是,我們可以禁用“Subscription Management”,然后配置成我們自己定義的Yum源,也就是Repository庫。
可以自定義本地Yum源, 這個很簡單,可參考之前的文檔。這里我們使用阿里雲開源鏡像。
阿里雲開源鏡像
https://mirrors.aliyun.com/repo/
https://mirrors.aliyun.com/repo/
下載CentOS-Base.repo 到/etc/yum.repos.d/
cd /etc/yum.repos.d/
wget https://mirrors.aliyun.com/repo/Centos-8.repo
cd /etc/yum.repos.d/
wget https://mirrors.aliyun.com/repo/Centos-8.repo
[root@wuhan2020 /]# cd /etc/yum.repos.d/ [root@wuhan2020 yum.repos.d]# wget https://mirrors.aliyun.com/repo/Centos-8.repo --2020-02-17 15:17:20-- https://mirrors.aliyun.com/repo/Centos-8.repo Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 47.246.28.228, 47.246.28.229, 47.246.28.224, ... Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|47.246.28.228|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 2595 (2.5K) [application/octet-stream] Saving to: ‘Centos-8.repo’ Centos-8.repo 100%[===========================================>] 2.53K --.-KB/s in 0s 2020-02-17 15:17:22 (40.7 MB/s) - ‘Centos-8.repo’ saved [2595/2595] [root@wuhan2020 yum.repos.d]# ls Centos-8.repo redhat.repo [root@wuhan2020 yum.repos.d]# mv redhat.repo redhat.repo_bak
####修改以下兩個文件的Enable=0來禁用Subscription Management的提示。
[root@wuhan2020 yum.repos.d]# vi /etc/yum/pluginconf.d/product-id.conf
[root@wuhan2020 yum.repos.d]# vi /etc/yum/pluginconf.d/subscription-manager.conf
[root@wuhan2020 yum.repos.d]# vi /etc/yum/pluginconf.d/product-id.conf
[root@wuhan2020 yum.repos.d]# vi /etc/yum/pluginconf.d/subscription-manager.conf
[root@wuhan2020 yum.repos.d]# yum clean all
[root@wuhan2020 yum.repos.d]# yum makecache
[root@wuhan2020 yum.repos.d]# yum makecache
[root@wuhan2020 yum.repos.d]# yum repolist Last metadata expiration check: 0:00:25 ago on Mon 17 Feb 2020 03:21:58 PM +04. repo id repo name status AppStream CentOS-8 - AppStream - mirrors.aliyun.com 5,093 base CentOS-8 - Base - mirrors.aliyun.com 2,080 extras CentOS-8 - Extras - mirrors.aliyun.com 3 [root@wuhan2020 yum.repos.d]# yum grouplist Last metadata expiration check: 0:00:31 ago on Mon 17 Feb 2020 03:21:58 PM +04. Available Environment Groups: Server Minimal Install Workstation Custom Operating System Virtualization Host Installed Environment Groups: Server with GUI Installed Groups: Legacy UNIX Compatibility Container Management Development Tools Graphical Administration Tools Headless Management Network Servers Security Tools System Tools Available Groups: .NET Core Development RPM Development Tools Scientific Support Smart Card Support [root@wuhan2020 yum.repos.d]#
2. 安裝並測試thefuck應用
需要先安裝Python, Pip, Python-Devel
RHEL8默認已安裝了Python3.6。
[root@wuhan2020 bin]# find /usr/bin/ -name python* /usr/bin/python3.6 /usr/bin/python3.6m /usr/bin/python3 /usr/bin/python-argcomplete-check-easy-install-script /usr/bin/python-argcomplete-tcsh [root@wuhan2020 bin]# ln -s /usr/bin/python3.6 /usr/bin/python [root@wuhan2020 /]# python -V Python 3.6.8
需要手動安裝python3-devel
[root@wuhan2020 ~]# yum install python3-devel
安裝Pip
[root@wuhan2020 /]# python get-pip.py Collecting pip Downloading pip-20.0.2-py2.py3-none-any.whl (1.4 MB) |████████████████████████████████| 1.4 MB 1.3 MB/s Collecting wheel Downloading wheel-0.34.2-py2.py3-none-any.whl (26 kB) Installing collected packages: pip, wheel Attempting uninstall: pip Found existing installation: pip 9.0.3 Uninstalling pip-9.0.3: Successfully uninstalled pip-9.0.3 Successfully installed pip-20.0.2 wheel-0.34.2 After the preparation environment is ready, start installing "Thefuck": Install python pip [root@wuhan2020 log]# pip -V pip 20.0.2 from /usr/local/lib/python3.6/site-packages/pip (python 3.6) Install the setuptools module [root@wuhan2020 log]# pip install -U setuptools Requirement already up-to-date: setuptools in /usr/local/lib/python3.6/site-packages (45.2.0)
安裝thefuck
root@wuhan2020 ~]# python3 -m pip install thefuck Collecting thefuck Using cached thefuck-3.29-py2.py3-none-any.whl (109 kB) Collecting psutil Using cached psutil-5.6.7.tar.gz (448 kB) Requirement already satisfied: six in /usr/lib/python3.6/site-packages (from thefuck) (1.11.0) Requirement already satisfied: colorama in /usr/local/lib/python3.6/site-packages (from thefuck) (0.4.3) Requirement already satisfied: decorator in /usr/lib/python3.6/site-packages (from thefuck) (4.2.1) Requirement already satisfied: pyte in /usr/local/lib/python3.6/site-packages (from thefuck) (0.8.0) Requirement already satisfied: wcwidth in /usr/local/lib/python3.6/site-packages (from pyte->thefuck) (0.1.8) Building wheels for collected packages: psutil Building wheel for psutil (setup.py) ... done Created wheel for psutil: filename=psutil-5.6.7-cp36-cp36m-linux_x86_64.whl size=282020 sha256=d257a6b535f7e092f19dcb2e28d3940232bb33ecf2c960998c05bdcade73ff74 Stored in directory: /root/.cache/pip/wheels/b2/b3/a3/551db06cebc9141c437c6b58aa751d3670471494e9f6d1428d Successfully built psutil Installing collected packages: psutil, thefuck Successfully installed psutil-5.6.7 thefuck-3.29
配置環境變量
可以添加到bashrc或者/etc/profile文件都行。
[root@wuhan2020 /]# vi /etc/profile
###修改profile文件,在末尾下面一行內容
alias fuck='eval $(thefuck $(fc -ln -1)); history -r'
[root@wuhan2020 /]# hostnamectl Static hostname: wuhan2020 Icon name: computer-laptop Chassis: laptop Machine ID: 601eca308ef84823a9e0a775d944fa23 Boot ID: 2b616f1426814536b6cd7a469718f588 Operating System: Red Hat Enterprise Linux 8.1 (Ootpa) CPE OS Name: cpe:/o:redhat:enterprise_linux:8.1:GA Kernel: Linux 4.18.0-147.el8.x86_64 Architecture: x86-64 [root@wuhan2020 /]# hostnamcl bash: hostnamcl: command not found... [root@wuhan2020 /]# fuck hostnamectl [enter/↑/↓/ctrl+c] Static hostname: wuhan2020 Icon name: computer-laptop Chassis: laptop Machine ID: 601eca308ef84823a9e0a775d944fa23 Boot ID: 2b616f1426814536b6cd7a469718f588 Operating System: Red Hat Enterprise Linux 8.1 (Ootpa) CPE OS Name: cpe:/o:redhat:enterprise_linux:8.1:GA Kernel: Linux 4.18.0-147.el8.x86_64 Architecture: x86-64 [root@wuhan2020 /]#
=====
在安裝thefuck時,有遇到如下錯誤,原因是未安裝Python3-devel.
[root@wuhan2020 ~]# python3 -m pip install thefuck Collecting thefuck Using cached thefuck-3.29-py2.py3-none-any.whl (109 kB) Collecting psutil Using cached psutil-5.6.7.tar.gz (448 kB) Requirement already satisfied: six in /usr/lib/python3.6/site-packages (from thefuck) (1.11.0) Requirement already satisfied: decorator in /usr/lib/python3.6/site-packages (from thefuck) (4.2.1) Requirement already satisfied: colorama in /usr/local/lib/python3.6/site-packages (from thefuck) (0.4.3) Requirement already satisfied: pyte in /usr/local/lib/python3.6/site-packages (from thefuck) (0.8.0) Requirement already satisfied: wcwidth in /usr/local/lib/python3.6/site-packages (from pyte->thefuck) (0.1.8) Building wheels for collected packages: psutil Building wheel for psutil (setup.py) ... error ERROR: Command errored out with exit status 1: command: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-a1ke_1aj/psutil/setup.py'"'"'; __file__='"'"'/tmp/pip-install-a1ke_1aj/psutil/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', creating build/temp.linux-x86_64-3.6 creating build/temp.linux-x86_64-3.6/psutil gcc -pthread -Wno-unused-result -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DPSUTIL_POSIX=1 -DPSUTIL_VERSION=567 -DPSUTIL_LINUX=1 -I/usr/include/python3.6m -c psutil/_psutil_common.c -o build/temp.linux-x86_64-3.6/psutil/_psutil_common.o psutil/_psutil_common.c:9:10: fatal error: Python.h: No such file or directory #include <Python.h> ^~~~~~~~~~ compilation terminated. error: command 'gcc' failed with exit status 1 ---------------------------------------- ERROR: Failed building wheel for psutil Running setup.py clean for psutil Failed to build psutil Installing collected packages: psutil, thefuck Running setup.py install for psutil ... error ERROR: Command errored out with exit status 1: command: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-a1ke_1aj/psutil/setup.py'"'"'; __file__='"'"'/tmp/pip-install-a1ke_1aj/psutil/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-w70uqb0g/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.6m/psutil cwd: /tmp/pip-install-a1ke_1aj/psutil/ Complete output (44 lines): …… creating build/temp.linux-x86_64-3.6 creating build/temp.linux-x86_64-3.6/psutil gcc -pthread -Wno-unused-result -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DPSUTIL_POSIX=1 -DPSUTIL_VERSION=567 -DPSUTIL_LINUX=1 -I/usr/include/python3.6m -c psutil/_psutil_common.c -o build/temp.linux-x86_64-3.6/psutil/_psutil_common.o psutil/_psutil_common.c:9:10: fatal error: Python.h: No such file or directory #include <Python.h> ^~~~~~~~~~ compilation terminated. error: command 'gcc' failed with exit status 1 ---------------------------------------- ERROR: Command errored out with exit status 1: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-a1ke_1aj/psutil/setup.py'"'"'; __file__='"'"'/tmp/pip-install-a1ke_1aj/psutil/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-w70uqb0g/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.6m/psutil Check the logs for full command output.
參考以下安裝文檔
https://github.com/nvbn/thefuck