ubunto apt config proxy 配置代理或者运行在代理网络的环境下

本文详细介绍了如何在主机代理网络环境下,通过修改/etc/apt/apt.conf文件、配置环境变量以及使用sudo add-apt-repository命令解决Ubuntu无法下载更新软件的问题。包括更新openjdk8的具体步骤。

问题描述:


如果你是在主机 代理网络的环境下,并且客户端你有创建了虚拟机的Linux ,你会发现很多时候并不能在虚拟机下载更新软件。

比如:unbutu 下面apt-get update很多时候都是失败的。


解决方法:

对于ubuntu 可以采用如下方法。

1、在/etc/apt/文件夹下面新建立 apt.conf 文件

然后添加

ubuntu@ubuntu:~$ cat /etc/apt/apt.conf
Acquire::http::Proxy "http://Username:Password@proxy.xxx.xxx.xxx.xxx:8080";

说明:如果代理没有密码,可以不用写,直接如下。

Acquire::http::Proxy "http://proxy.xxx.xxx.xxx.xxx:8080";

2、配置环境变量 

在  /etc/environment 中添加

export http_proxy=http://username:password@host:port/
export https_proxy=https://username:password@host:port/

3、然后运行sudo    

sudo add-apt-repository XXX  ##如果有代理的情况下加不上可以 在不适用代理的网络里面加 比如guest网络

 -E, --preserve-env

 Indicates to the security policy that the user wishes to preserve their existing environment variables.  The security

policy may return an error if the user does not have permission to preserve the environment.

add-apt-repository adds a PPA to your list of sources, so that Ubuntu knows to look for updates from that PPA as well as from the official Ubuntu sources. Usually this is used to allow developers to provide updates more quickly than those in the official Ubuntu repositories.

apt-get update tells apt-get to update its database of what packages can be installed and where to install them from. In this case, apt-get will see your newly-added PPA and discover that ppa:maco.m/ruby has the newest version of rubygems that it knows about, so it will make a note to install rubygems from the PPA next time someone asks to install it.

apt-get install causes apt-get to find the package in its database and download and install the indicated file. In this case, it will find the rubygems package, download it from ppa:maco.m/ruby, and install it.

实  例:

更新 ubutu 的openjdk8 步骤如下:

可以参考http://ubuntuhandbook.org/index.php/2015/01/install-openjdk-8-ubuntu-14-04-12-04-lts/

  1. sudo add-apt-repository ppa:openjdk-r/ppa ##如果有代理的情况下加不上可以 在不适用代理的网络里面加 比如guest网络 下面 先加上这个

  2. sudo apt-get update

  3. sudo apt-get install openjdk-8-jdk

  4. sudo update-alternatives --config java

   ## 如果你安装好了,对于你的系统中有多个jdk版本的话,需要运行。

        ##  enter the number for which JDK to use of your choice.

 5. sudo update-alternatives --config javac

        ## 如果你安装好了,对于你的系统中有多个jdk版本的话,需要运行。

转载于:https://my.oschina.net/u/2308739/blog/657406

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值