Reputation: 2097
While I spend most of my career on the Microsoft stack as a full-stack web developer - I have, on occasion, made my way into the *NIX side of things.. built out a FreeBSD web server here, played with Caldera Linux once over there, and am currently doing some web deployment using a Google cloud VM that is running Ubuntu...
TL,DR So, if I forked a repo onto my GitHub account- all for the purposes of then cloning it into my Ubuntu server where I'll then compile and run the web application..
What is the professionally expected location that I should put that 'cloned' source code? I googled around a bit to get a better grasp of what the various linux directories are for.. but.. I need a good SO answer... so... where would you put it?
/usr/src/MyGitRepos
..that sounded good to me.. but.. what would you do?
Upvotes: 20
Views: 31062
Reputation: 2998
I would say that the user's home
subfolder is the best location choice for cloning a repo. On Linux/Unix/POSIX compliant shells, it is often abbreviated with ~
.
Many people choose a location like ~/src/
for cloning their repos.
~
will resolve to /home/[username]
, and src
is a subfolder that you can create there.
Personally, I disagree with people suggesting /usr
, /usr/local
or /opt
for storing git repos, because these folders are intended to store software (binaries, not code):
/usr
itself stores binaries (intended to host installed software)./usr/local
is again intended for locally installed software that is independent from the distro itself./opt
is generally intended for again storing installed software that is optional, in the sense that it should be removable by simply deleting its folder within opt
.Additionally, I believe that a git repo cloned copy is not intended to be shared between users and must not be used like that. If sharing of the code is necessary, the repo should be cloned by each user using it, rather than having different users sharing the same folder. Otherwise, conflicts in the modifications to the code will certainly happen soon.
Finally, if disk usage is a concern, it probably means that the repo is used improperly to store large files rather than just source code. Although in theory this can be done, with things like git-lfs
which allows to store large assets within a repo, then the work machine should be provisioned to satisfy the disk space requirement for multiple repo clones done by different users.
Instead of storing large assets in the same repo that owns the code is probably advisable to move the large assets into a separate central location, which can be an untracked folder, or a git-lfs
repo which can then be cloned only once per machine. In order to simplify the referral to the centralized assets from the code repo, you can use symbolic links placed in the code repo which point to the assets (symbolic links are tracked by git).
Upvotes: 3
Reputation: 34175
What is the professionally expected location
If as you say you're deploying an app that's compiled from source, then there's no such location. In a professional environment your sources don't go on the servers.
From most professional to "it works" solutions:
Build system packages outside of your production environment. That means you have a repository of both previously deployed versions and have a package manifest including both build and runtime dependencies. That means you can rebuild your app the same way every time. For installation, install the built package. (this applies to deb, rpm, etc.)
Build tarballs with binaries in a predictable environment (developer's box). That means you run (for example, if you're using autotools) ./configure --prefix=/opt/your_app && make install DESTDIR=/tmp/somedirectory
- now you can pack the /tmp/somedirectory/opt/your_app
contents, copy it to a server and unpack it to /opt/your_app
.
Clone it wherever (your home directory), then build, then install in the destination. Popular destinations are /opt/app_name
and /usr/local
.
The solution depends on how professional the deployment really is, how many servers you've got, have you got test/production environment, etc.
Upvotes: 11
Reputation: 5617
When it's to be used by a single unix user, somewhere in $HOME
is quite reasonable to me. If the repo is meant to be used from other user as well, /opt
is considerable.
Upvotes: 3
Reputation: 353
I wouldn't say there is a standard assumed place, especially if the server is specifically for this application. Putting a folder for it in the /home/user directory should be fine even, or organising it any way you see fit from that point:
/home/user/app-goes-here/app.js
Just keep it simple :)
Upvotes: 3