且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何更改apt-get安装目录

更新时间:2023-02-02 21:01:13

我能想到的***方法是使用符号链接

Best way I can think of is to use a symbolic link

请注意,并非所有程序都安装在同一目录中,/opt可能不是***的移动方法. (例如,只移动一个文件夹/程序,请参见结尾)

note that not all programmes are installed to the same directory and /opt may not be the best thing to move. (see end for example of moving only one folder/program)

这就是我对EasyPeasy(Ubuntu 10.04)所做的

This is what I did with EasyPeasy (Ubuntu 10.04)

仔细遵循此代码,如果使用不正确,某些命令可能会删除重要文件.

Follow this code carefully some of the commands can delete important files if used incorrectly.

首先,您需要确保/opt(或发行版的默认apt-get安装目录)为空.如果您最有可能在opt文件夹中有数据,则可以先将其移动到其他位置以进行安全保存:

First you need to make sure /opt (or your distros default apt-get install directory) is empty. If you have data in the opt folder, which you most likely do, you can move it to somewhere else first for safe keeping:

sudo mkdir /New_Location/newtmp                                      # Generates Temporary Folder for Programs 
sudo cp -a /opt/* /New_Location/newtmp                               # Moves Programs to Temp folder

一旦备份,您可以删除原始目录:

Once backed up you can remove the original directory:

sudo rm -rf /opt/                                                    # Removes opt directory

然后,您可以在具有大量空间的驱动器中创建新的Program Files文件夹,并创建符号链接:

You can then create your new Program Files folder in a drive with lots of space and create a symbolic link:

sudo mkdir /New_Location/Program-Files                               # Generates New Program Directory
sudo ln -s /New_Location/Program-Files /opt                          # Creates Symbolic Link

最后将所有旧程序文件移动到新文件夹并清理临时数据:

Finally move all your old program files to your new folder and clean up the temporary data:

sudo cp -a /New_Location/newtmp/* /New_Location/Program-Files        # Moves Programs to Program Files Folder 
sudo rm -rf /New_Location/newtmp/                                    # Removes Temp folder

如果您只想移动占用大量空间的单个程序,则可以使用相同的过程.

If you only wanted to move a single program which is taking up a hunk of your space you could use the same process.

例如: 要移动Java(JVM大约300MB),请执行以下操作. 使用磁盘使用率分析器检查Java目录. 我的是/usr/lib/jvm

eg: to move Java (JVM approx 300MB) do the following. check directory of java using disk usage analyser. mine is /usr/lib/jvm

sudo mkdir /New_Location/Program-Files/Java                          # Generates New Program Directory
sudo cp -a /usr/lib/jvm/* /New_Location/Program-Files/Java            # Moves Program to new folder
sudo rm -rf /usr/lib/jvm                                             # Removes opt directory
sudo ln -s /New_Location/Program-Files/Java /usr/lib/jvm             # Creates Symbolic Link

此时***重启并清除缓存.

Its best at this point to do a restart which should clear the cache.

快乐黑客 情报有限