build ubuntu from source

本文介绍如何使用apt-build工具从源代码构建整个Ubuntu系统及应用程序,包括安装配置apt-build、设置编译选项以及使用apt-build命令进行系统更新、升级和应用安装等操作。

from:

http://askubuntu.com/questions/29856/build-ubuntu-from-source-for-speed

首先答案是可以的。


Is is possible to build Ubuntu from source to get the same kind of benefit?

I am not sure about the benefits if you have fairly new hardware components but for the "Ubuntu from source" part of the question the answer is YES, you can build not only your favorite applications from source, but the entire operating system.

Here is how:

You need to install apt-build. Its a comandline tool like apt-get, but instead of downloading and installing the binary package, apt-build downloads the source code of the package, compiles it and then installs it to your system.

After you install it with

sudo apt-get install apt-build

you will be asked for an optimization level (medium is ok), whether you want to create an apt-build repo for APT (Yes) and a question about processor architecture (my intel i7 is considered core2 ). Of course all options can be reconfigured in this way:

dpkg-reconfigure apt-build

The above command offers two additional options for the gcc compiler and make builder. Their descriptions can be found in system manuals: man gcc and man make.

For a manual and available command options check

man apt-build

But the most useful are:

  • apt-build update — updates repo list, (like apt-get update)
  • apt-build upgrade — updates operating system, (like apt-get upgrade)
  • apt-build install program — installs an application,(like apt-get install)
  • apt-build world — something for hard-core users, it recompiles whole system!

For example:

Lets say you want to compile/install Gedit. Instead of apt-get install you just do

sudo apt-build install gedit

Apt-build makes use of deb-src entries contained in the /etc/apt/sources.list file so the compilation and installation processes are fully automatic (similar to emerge found in Gentoo). Apt-build downloads sources of the main application and its dependencies, compiles them, creates a deb package, and finally installs the package.

Some notes about apt-build world.

In my opinion don't attempt it, unless you have 24 or more hours available !

If so first thing you should, remove/disable/uninstall any third party applications (it better to do in a fresh install of Ubuntu) and then do :

sudo su
dpkg --get-selections | awk '{if ($2 == "install") print $1}'> /etc/apt/apt-build.list
exit

The above command will copy your full list of system packages to apt-build.list so that they can be compiled from source.Open that file

sudo gedit /etc/apt/apt-build.list

and remove any GCC/G++ entry

Then you can do :

sudo apt-build world

I suggest to add two options — --yes and --force-yes — to make the rebuilding process fully automatic.

share improve this answer

<think>我们正在回答用户的问题:如何从源代码构建软件(how to build software from source code) 根据引用内容,我们可以总结出从源代码构建软件的一般步骤和注意事项。 引用[1]提到构建NCL需要Fortran编译器和ANSI C编译器。 引用[2]提到构建Qt的原因可能是需要不同的配置选项。 引用[3]提到运行时需要确保依赖库(如ICU DLLs)可被找到。 引用[4]展示了使用conda安装依赖包的命令。 因此,构建软件的一般步骤包括: 1. 获取源代码(如通过版本控制系统下载) 2. 安装必要的编译工具(如C/C++编译器、构建工具链) 3. 安装依赖库(可能需要使用包管理器或从源码构建) 4. 配置构建选项(如使用./configure或cmake) 5. 编译(如使用make) 6. 安装(如使用make install) 7. 配置运行时环境(如设置环境变量) 我们将按照这些步骤详细说明。</think>### 如何从源代码构建软件 从源代码构建软件需要以下核心步骤,不同项目可能有特定要求,但通用流程如下: #### **1. 准备编译环境** - **安装基础工具链**: - C/C++编译器(如GCC/Clang) - Fortran编译器(科学计算项目常用,如`gfortran`)[^1] - 构建工具(如`make`, `cmake`, `autotools`) - 包管理器(如`conda`用于管理依赖)[^4] ```bash # Ubuntu示例 sudo apt install build-essential gfortran cmake ``` #### **2. 获取源代码** - 通过版本控制工具(如Git)或直接下载源码包: ```bash git clone https://github.com/项目地址 # 从Git仓库获取 wget https://example.com/project.tar.gz && tar -xvf project.tar.gz # 下载压缩包 ``` 引用[3]强调需确保源码完整(如Qt需包含所有子模块)。 #### **3. 安装依赖项** - **库依赖**:如ICU(Unicode处理)、OpenSSL等,需提前安装: ```bash sudo apt install libicu-dev libssl-dev # Ubuntu示例 ``` - **包管理器安装**(如conda): ```bash conda install -c conda-forge 依赖包名 # 引用[4] ``` #### **4. 配置构建选项** - 运行配置脚本,指定安装路径、功能模块等: ```bash ./configure --prefix=/usr/local --enable-feature # 传统项目 cmake -DCMAKE_INSTALL_PREFIX=/opt/project -DBUILD_SHARED_LIBS=ON . # CMake项目 ``` 引用[2]指出:自定义配置可优化平台适配性(如禁用不需要的模块)。 #### **5. 编译与安装** - 编译代码并安装到系统: ```bash make -j$(nproc) # 并行编译(利用多核CPU) sudo make install # 安装到系统目录 ``` - 大型项目(如Qt)可能需数小时。 #### **6. 配置运行时环境** - 设置动态库路径(避免运行时错误): ```bash export LD_LIBRARY_PATH=/安装路径/lib:$LD_LIBRARY_PATH # Linux # 或永久添加到~/.bashrc ``` 引用[3]强调:Windows需将DLL放入程序目录或添加至`PATH`。 #### **7. 验证安装** - 检查版本或运行测试: ```bash 软件名 --version make test # 运行测试用例 ``` ### 关键注意事项 1. **文档优先**:始终查看项目`README.md`或`INSTALL`文件,不同项目流程可能差异较大。 2. **依赖管理**:缺失依赖是常见失败原因,可用`ldd`(Linux)检查动态库。 3. **权限问题**:安装到系统目录需`sudo`,推荐用户级安装(`--prefix=$HOME/.local`)。 4. **调试构建**:开发时添加调试符号(如`./configure --debug`)。 > **示例:构建Python包** > ```bash > git clone https://github.com/project.git > cd project > pip install -r requirements.txt # 安装Python依赖 > python setup.py build_ext --inplace # 编译C扩展 > python -m pytest tests/ # 运行测试 > ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值