What's the 'standard' directory location to use when cloning a Git repo onto a LINUX machine

12,713

Solution 1

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:

  1. 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.)

  2. 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.

  3. 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.

Solution 2

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 :)

Solution 3

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.

Share:
12,713

Related videos on Youtube

bkwdesign
Author by

bkwdesign

Full stack web developer. Familiar with custom development inside SharePoint and Microsoft Dynamics AX when I'm not busy raising my family SOreadytohelp

Updated on September 18, 2022

Comments

  • bkwdesign
    bkwdesign over 1 year

    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?

  • bkwdesign
    bkwdesign over 8 years
    yeah, putting it in the home/user/ location .. makes sense.. that's basically the direction I was looking for - along with your tip that there's not a standard place. Just needed some independent verification that my gut sense was going the right direction.. I don't consider myself *NIX-y enough to trust my instincts ;-)
  • bkwdesign
    bkwdesign over 8 years
    good to know - yes, this is a freelance gig - I'm basically putting some servers together for a client who will then take over everything - my appearance on this set-up is going to be brief
  • bkwdesign
    bkwdesign over 8 years
    ha ha.. now I knew this from developing ASP.NET.. only the "bin" folder gets published.. I just didn't have the right frame of mind .. I get all "hacky" when I'm doing linux stuff and forget the obvious (or, well.... maybe.. not so obvious) I really appreciate the listing out of the steps with the command-line code snippets. This is the answer I was looking for - putting me on a sane path.
  • Nodal
    Nodal over 8 years
    Glad I could be of assistance :) as long it's it's not some big enterprise level deployment (and I assume you would be given instructions about this if it was) then I see no reason why this wouldn't be suitable.
  • M.M
    M.M over 8 years
    If you put it somewhere other than $HOME there's a potential problem; if a different user comes along and tries to run a git command on the directory then you will get into difficulties (that user might not have permissions to modify the files in the .git subdirectory that have your user id on them, for example). My suggestion would be that if you intend collaborative development then each user clones their own copy to their $HOME ; but if you intend to use the results in a read-only way, then clone it somewhere and rm -rf .git .
  • bkwdesign
    bkwdesign over 8 years
    right, I did a recursive chown command right before I executed the make ..which allowed all the package management stuff to succeed.. but.. I see what you're saying.. it succeeded for me