macos 如何在 Mac OS X 上使用 /home 目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1362703/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I use the /home directory on Mac OS X
提问by Alan W. Smith
I've got a Mac that I can run either the Leopard (10.5) or Snow Leopard (10.6) version of OS X on. I'm using it to do web development/testing before publishing files to my production host.
我有一台 Mac,可以在其上运行 Leopard (10.5) 或 Snow Leopard (10.6) 版本的 OS X。在将文件发布到我的生产主机之前,我使用它进行 Web 开发/测试。
On the production host my site's doc root is under the home directory (e.g. /home/stimulatingpixels/public_html) and I'd like to duplicate that location on the Mac. Unfortunately, their is a hidden and lock placeholder on the Mac that looks like a mounted drive with nothing in it sitting in the /home location.
在生产主机上,我网站的文档根目录位于主目录下(例如 /home/stimulatingpixels/public_html),我想在 Mac 上复制该位置。不幸的是,它们是 Mac 上的一个隐藏和锁定占位符,看起来像一个安装的驱动器,里面没有任何东西位于 /home 位置。
I know from experience that it's unwise to move this and drop in your own /home directory because upgrades can cause it to be erased (and it doesn't get stored in the TimeMachine backup, by the way).
我从经验中知道,将它移动并放入您自己的 /home 目录是不明智的,因为升级可能会导致它被删除(顺便说一下,它不会存储在 TimeMachine 备份中)。
So, the question, is there anyway to safely use /home on a Mac either Leopard or Snow Leopard?
那么,问题是,无论如何可以在 Leopard 或 Snow Leopard 的 Mac 上安全地使用 /home 吗?
(Note: I realize this is very Mac specific and will be asking it in an Apple forum as well. Just wanted to ask here in addition to cover all the bases.)
(注意:我意识到这是非常 Mac 特有的,也会在 Apple 论坛中询问它。除了涵盖所有基础之外,还想在这里提问。)
Update: To help describe why I want to do this, in addition to the front end web site, I've got a series of scripts that I'd like to run as well. One of the main goals with being able to use the /home directory (and more specifically the same path from the servers root) is so that can use the same output paths on the development mac as well be used on the production server. I know there are ways to work around this, but I'd rather not have to deal with it. The real goal is to have all the files on the development Mac have the same filepath from the / root of the directory tree as the production server.
更新:为了帮助描述我为什么要这样做,除了前端网站之外,我还有一系列我想运行的脚本。能够使用 /home 目录(更具体地说是来自服务器根目录的相同路径)的主要目标之一是可以在开发 mac 上使用相同的输出路径,也可以在生产服务器上使用。我知道有很多方法可以解决这个问题,但我宁愿不必处理它。真正的目标是让开发 Mac 上的所有文件从目录树的 / 根目录具有与生产服务器相同的文件路径。
Another Update: The other reason that I forgot to mention earlier for this is setting up .htaccess paths when using basic authentication. Since those paths are from the file system root instead of the website docroot, they end up going through "/home" when that's part of the tree.
另一个更新:我之前忘记提及的另一个原因是在使用基本身份验证时设置 .htaccess 路径。由于这些路径来自文件系统根目录而不是网站 docroot,当它是树的一部分时,它们最终会通过“/home”。
回答by Alan W. Smith
NOTE: As of 2015, I no longer use or recommend this method. Instead I use Vagrantto setup virtual machines for dev and testing. It's free, relatively easy, and allows better matching of the production environment. It completely separates the development environment and you can make as many as you need. Highly recommended. I'm leaving the original answer below for posterity's sake.
注意:截至 2015 年,我不再使用或推荐此方法。相反,我使用Vagrant为开发和测试设置虚拟机。它是免费的,相对容易,并且可以更好地匹配生产环境。它完全分离了开发环境,您可以根据需要制作多个。强烈推荐。为了后人的缘故,我将在下面留下原始答案。
I found an answer here on the Apple forums.
我在 Apple 论坛上找到了答案。
In order to reclaim the /home
directory, edit the /etc/auto_master
file and comment out (or remove) the line with /home
in it. You'll need to reboot after this for the change to take effect (or, per nilbus' comment, try running sudo automount -vc
). This works with Mac OS X 10.5 (Leopard). Your millage may vary for different versions, but it should be similar.
为了回收/home
目录,编辑/etc/auto_master
文件并注释掉(或删除)其中的行/home
。您需要在此之后重新启动才能使更改生效(或者,根据 nilbus 的评论,尝试运行sudo automount -vc
)。这适用于 Mac OS X 10.5 (Leopard)。您的 Millage 可能因不同版本而异,但应该是相似的。
As noted on that forum post, you should also be aware that Time Machine automatically excludes the /home
directory and does notback it up.
正如该论坛帖子所述,您还应该知道Time Machine 会自动排除该/home
目录并且不会对其进行备份。
One note of warning, make sure to back up your /home
directory manually before doing a system update. I believe one of the updates I did (from 10.6 to 10.7 for example) wiped out what I has stored in /home
without warning. I'm not 100% sure that's what happened, but it's something to be on the lookout for.
一个警告,确保/home
在进行系统更新之前手动备份您的目录。我相信我所做的更新之一(例如从 10.6 到 10.7)在/home
没有警告的情况下抹去了我存储的内容。我不是 100% 确定这就是发生的事情,但这是需要注意的事情。
回答by KurtB
Putting it all together from the tips and hints above:
从上面的提示和提示中将所有内容放在一起:
edit
/etc/auto_master
# comment out the line with/home
in it.remount:
sudo automount -vc
make a softlink to the mac-ified dir:
sudo ln -s $HOME /home/$USER
编辑
/etc/auto_master
#注释掉其中的行/home
。重新安装:
sudo automount -vc
制作一个到 mac-ified 目录的软链接:
sudo ln -s $HOME /home/$USER
At that point, your paths should match-up to your production paths. env
vars will still point to /Users/xxxx
, but anything you hard-code in a path in your .bashrc
--or say, in ~/.pip/pip.conf
-- should be essentially equivalent. Worked for me.
那时,您的路径应该与您的生产路径相匹配。env
vars 仍将指向/Users/xxxx
,但是您在您的路径中硬编码的任何内容 -.bashrc
或者说, in ~/.pip/pip.conf
- 应该本质上是等效的。对我来说有效。
re: "The real goal is to have all the files on the development Mac have the same filepath from the / root of the directory tree as the production server."
回复:“真正的目标是让开发 Mac 上的所有文件在目录树的 / 根目录中具有与生产服务器相同的文件路径。”
On production, my deploy work might happen in /opt/projects/projname
, so I'll just make sure my account can write into /opt/projects
and go from there. I'd start by doing something like this:
在生产,我的部署工作可能发生的/opt/projects/projname
,所以我就确保我的帐户可以写入/opt/projects
,并从那里走。我首先做这样的事情:
sudo mkdir /opt/projects
sudo chown $USER /opt/projects
mkdir /opt/projects/projname
cd /opt/projects/projname
sudo mkdir /opt/projects
sudo chown $USER /opt/projects
mkdir /opt/projects/projname
cd /opt/projects/projname
With LVM, I'll set a separate partition for /opt/
, and write app data there instead of $HOME
. Then, I can grow the /opt
file system in cases where I need more disk space for a project (LVM is your friend.)
使用 LVM,我将为 设置一个单独的分区/opt/
,并在那里写入应用程序数据而不是$HOME
. 然后,我可以/opt
在需要更多磁盘空间用于项目的情况下扩展文件系统(LVM 是您的朋友。)
回答by Marco Torchiano
I tried it on Yosemite (OS X 10.10.1) the sudo automount -vc
didn't work, I had to use sudo umount /home
.
我在 Yosemite (OS X 10.10.1) 上试过了,没用sudo automount -vc
,我不得不使用sudo umount /home
.
Therefore my workflow would be:
因此我的工作流程是:
# comment out line starting with /home
sudo vi "+g/^\/home/s/\//#\//" "+x" /etc/auto_master
sudo umount /home
# link actual home directory (/Users/<user>) to new 'home' (/home/<user>)
ln -s $HOME /home/$USER
# comment out line starting with /home
sudo vi "+g/^\/home/s/\//#\//" "+x" /etc/auto_master
sudo umount /home
# link actual home directory (/Users/<user>) to new 'home' (/home/<user>)
ln -s $HOME /home/$USER
回答by Evernoob
Why don't you just run MAMP and use the Sites directory? You can develop off localhost and just have a bunch of aliases for your sites. I'm not sure why you specifically need to use the home directory.
为什么不直接运行 MAMP 并使用 Sites 目录?您可以在本地主机之外进行开发,并且只需为您的站点设置一堆别名。我不确定您为什么特别需要使用主目录。
EDIT: Ok, I think you are going about solving your problem the wrong way.
编辑:好的,我认为您正在以错误的方式解决您的问题。
If it's HTML paths you are worried about, the begin everything with a slash "/" which will default it to the home dierectory.
如果您担心的是 HTML 路径,则所有内容都以斜杠“/”开头,这将默认为主目录。
If it's the references in your PHP, then you need to create a global (or similar) and set it as the root of your site. Then you can reference everything from the global and when you move the site from dev to production all you need to change is the global.
如果是 PHP 中的引用,则需要创建一个全局(或类似的)并将其设置为站点的根目录。然后您可以引用全局中的所有内容,当您将站点从开发转移到生产时,您需要更改的只是全局。
Trying in a round-about way to develop from /home because it looks more like the production server is a bad idea.
尝试以一种迂回的方式从 /home 开发,因为它看起来更像是生产服务器是一个坏主意。
Install MAMP, create the global somewhere high in the hierarchy and start re-referencing. It'll be less pain in the long run.
安装 MAMP,在层次结构的较高位置创建全局并开始重新引用。从长远来看,它会减少痛苦。