首頁  >  文章  >  系統教程  >  如何在非 root 使用者權限下安裝軟體並設定環境變數?

如何在非 root 使用者權限下安裝軟體並設定環境變數?

WBOY
WBOY原創
2024-06-16 15:51:25560瀏覽

如何在非 root 用户权限下安装软件并设置环境变量?

文章目錄

情況

使用root使用者linux使用root使用者linux壓縮指令,由於權限夠大,所以做哪些事都好弄

非root用戶,權限低時linux系統怎麼樣,連yuminstall都無法使用,那要如何安裝軟體呢

安裝rpm包

1、以安裝wget工具為例

先在windows瀏覽器上下載一個wget的rpm包

http://www.rpmfind.net/linux/centos/7.9.2009/os/x86_64/Packages/wget-1.14-18.el7_6.1.x86_64.rpm

之後模擬離線安裝

linux使用root用户_用户使用报告模板_用户使用报告

#2、使用非root使用者登入linux系統

<span class="token comment"># 尝试安装yumdownloader,不行的,需要root权限</span>
<span class="token punctuation">[</span>nim01@svngit root<span class="token punctuation">]</span>$ yum <span class="token function">install</span> yumdownloader
Loaded plugins: fastestmirror
You need to be root to perform this command.
<span class="token comment"># 尝试执行wget命令,不行,没有安装</span>
<span class="token punctuation">[</span>nim01@svngit root<span class="token punctuation">]</span>$ <span class="token function">wget</span>
bash: wget: <span class="token function">command</span> not found
<span class="token comment"># 尝试安装wget,不行的,需要root权限</span>
<span class="token punctuation">[</span>nim01@svngit root<span class="token punctuation">]</span>$ yum <span class="token function">install</span> <span class="token function">wget</span>
Loaded plugins: fastestmirror
You need to be root to perform this command.

將我們下載的wget.***.rpm包,上傳到linux系統中

Last login: Wed Dec2 09:44:05 2020
<span class="token punctuation">[</span>nim01@svngit ~<span class="token punctuation">]</span>$ <span class="token function">pwd</span>
/home/nim01
<span class="token comment"># root已经安装lrzsz了,直接上传</span>
<span class="token punctuation">[</span>nim01@svngit ~<span class="token punctuation">]</span>$ rz
<span class="token punctuation">[</span>nim01@svngit ~<span class="token punctuation">]</span>$ ll
total 548
-rw-r--r--. 1 nim01 nim01 560272 Dec22020 wget-1.14-18.el7_6.1.x86_64.rpm

用户使用报告_用户使用报告模板_linux使用root用户

#3、安裝rpm包

提取檔案

<span class="token comment"># 执行下面指令,从安装包中提取文件</span>
<span class="token punctuation">[</span>nim01@svngit ~<span class="token punctuation">]</span>$ rpm2cpio wget-1.14-18.el7_6.1.x86_64.rpm <span class="token operator">|</span> cpio -idvm
./etc/wgetrc
./usr/bin/wget
./usr/share/doc/wget-1.14
./usr/share/doc/wget-1.14/AUTHORS
./usr/share/doc/wget-1.14/COPYING
./usr/share/doc/wget-1.14/MAILING-LIST
./usr/share/doc/wget-1.14/NEWS
./usr/share/doc/wget-1.14/README
./usr/share/doc/wget-1.14/sample.wgetrc
./usr/share/info/wget.info.gz
./usr/share/locale/be/LC_MESSAGES/wget.mo
./usr/share/locale/bg/LC_MESSAGES/wget.mo
./usr/share/locale/ca/LC_MESSAGES/wget.mo
./usr/share/locale/cs/LC_MESSAGES/wget.mo
./usr/share/locale/da/LC_MESSAGES/wget.mo
./usr/share/locale/de/LC_MESSAGES/wget.mo
./usr/share/locale/el/LC_MESSAGES/wget.mo
./usr/share/locale/en_GB/LC_MESSAGES/wget.mo
./usr/share/locale/eo/LC_MESSAGES/wget.mo
./usr/share/locale/es/LC_MESSAGES/wget.mo
./usr/share/locale/et/LC_MESSAGES/wget.mo
./usr/share/locale/eu/LC_MESSAGES/wget.mo
./usr/share/locale/fi/LC_MESSAGES/wget.mo
./usr/share/locale/fr/LC_MESSAGES/wget.mo
./usr/share/locale/ga/LC_MESSAGES/wget.mo
./usr/share/locale/gl/LC_MESSAGES/wget.mo
./usr/share/locale/he/LC_MESSAGES/wget.mo
./usr/share/locale/hr/LC_MESSAGES/wget.mo
./usr/share/locale/hu/LC_MESSAGES/wget.mo
./usr/share/locale/id/LC_MESSAGES/wget.mo
./usr/share/locale/it/LC_MESSAGES/wget.mo
./usr/share/locale/ja/LC_MESSAGES/wget.mo
./usr/share/locale/lt/LC_MESSAGES/wget.mo
./usr/share/locale/nb/LC_MESSAGES/wget.mo
./usr/share/locale/nl/LC_MESSAGES/wget.mo
./usr/share/locale/pl/LC_MESSAGES/wget.mo
./usr/share/locale/pt/LC_MESSAGES/wget.mo
./usr/share/locale/pt_BR/LC_MESSAGES/wget.mo
./usr/share/locale/ro/LC_MESSAGES/wget.mo
./usr/share/locale/ru/LC_MESSAGES/wget.mo
./usr/share/locale/sk/LC_MESSAGES/wget.mo
./usr/share/locale/sl/LC_MESSAGES/wget.mo
./usr/share/locale/sr/LC_MESSAGES/wget.mo
./usr/share/locale/sv/LC_MESSAGES/wget.mo
./usr/share/locale/tr/LC_MESSAGES/wget.mo
./usr/share/locale/uk/LC_MESSAGES/wget.mo
./usr/share/locale/vi/LC_MESSAGES/wget.mo
./usr/share/locale/zh_CN/LC_MESSAGES/wget.mo
./usr/share/locale/zh_TW/LC_MESSAGES/wget.mo
./usr/share/man/man1/wget.1.gz
4030 blocks

查看

用户使用报告模板_linux使用root用户_用户使用报告

#

<span class="token comment"># 提取完之后,当前目录多了etc和usr两个目录</span>
<span class="token punctuation">[</span>nim01@svngit ~<span class="token punctuation">]</span>$ ll
total 548
drwxrwxr-x. 2 nim01 nim01 20 Dec2 10:13 etc
drwxrwxr-x. 4 nim01 nim01 30 Dec2 10:13 usr
-rw-r--r--. 1 nim01 nim01 560272 Dec22020 wget-1.14-18.el7_6.1.x86_64.rpm

查看

<span class="token comment"># 进入usr/bin目录,可以看到可执行的wget文件</span>
<span class="token punctuation">[</span>nim01@svngit ~<span class="token punctuation">]</span>$ <span class="token function">cd</span> usr/
<span class="token punctuation">[</span>nim01@svngit usr<span class="token punctuation">]</span>$ ll
total 0
drwxrwxr-x. 2 nim01 nim01 18 Dec2 10:13 bin
drwxrwxr-x. 6 nim01 nim01 54 Dec2 10:13 share
<span class="token punctuation">[</span>nim01@svngit usr<span class="token punctuation">]</span>$ <span class="token function">cd</span> bin/
<span class="token punctuation">[</span>nim01@svngit bin<span class="token punctuation">]</span>$ ll
total 412
-rwxr-xr-x. 1 nim01 nim01 418776 May 162019 <span class="token function">wget</span>

4、設定環境變數

用户使用报告_linux使用root用户_用户使用报告模板

#在家目錄中,直接編輯.bashrc文件,降低執行程式的路徑到系統PATH中

這樣linux使用root使用者,可以直接執行wget指令了

<span class="token comment"># .bashrc</span>
<span class="token comment"># Source global definitions</span>
<span class="token keyword">if</span> <span class="token punctuation">[</span> -f /etc/bashrc <span class="token punctuation">]</span><span class="token punctuation">;</span> <span class="token keyword">then</span>
<span class="token keyword">.</span> /etc/bashrc
<span class="token keyword">fi</span>
<span class="token comment"># Uncomment the following line if you don&#039;t like systemctl&#039;s auto-paging feature:</span>
<span class="token comment"># export SYSTEMD_PAGER=</span>
<span class="token comment"># User specific aliases and functions</span>
<span class="token function">export</span> PATH<span class="token operator">=</span><span class="token variable">$PATH</span><span class="token keyword">:</span><span class="token variable">$HOME</span>/usr/bin

儲存退出後

<span class="token comment"># 执行source,让修改生效</span>
<span class="token punctuation">[</span>nim01@svngit ~<span class="token punctuation">]</span>$ <span class="token function">source</span> .bashrc
<span class="token comment"># 执行wget,可正常使用</span>
<span class="token punctuation">[</span>nim01@svngit ~<span class="token punctuation">]</span>$ <span class="token function">wget</span>
wget: missing URL
Usage: <span class="token function">wget</span> <span class="token punctuation">[</span>OPTION<span class="token punctuation">]</span><span class="token punctuation">..</span>. <span class="token punctuation">[</span>URL<span class="token punctuation">]</span><span class="token punctuation">..</span>.
Try `wget --help&#039; <span class="token keyword">for</span> <span class="token function">more</span> options.

以上是如何在非 root 使用者權限下安裝軟體並設定環境變數?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn