I’ve been diving into using Ubuntu through the Windows Terminal, and I have to say, it’s pretty cool! But I keep running into this little hiccup that’s driving me a bit nuts. You know how when you open up a terminal session, it usually defaults to the home directory? Well, I’m not a huge fan of that directory, and I spend most of my time working in a specific folder for my projects. Honestly, it feels like I’m wasting so much time typing `cd path/to/my/project` every single time I open a new terminal.
I’ve tried looking around for ways to set a default directory, but I keep getting different pieces of advice or solutions that seem to work for some folks but not for others. Like, I’ve seen some threads mentioning editing the `.bashrc` file, and then there are others talking about the Windows Terminal settings itself. It’s all a bit confusing to me, especially since I’m relatively new to Ubuntu’s terminal.
What I’m really looking for is a straightforward way to set this up so that each time I launch Ubuntu in the Windows Terminal, I land right in my projects folder without any extra typing. Is there a specific command I need to add somewhere? Or maybe a setting I need to tweak? I really want to make my workflow smoother, but I just can’t seem to wrap my head around the best approach.
Also, if there are any tips on how to do this without breaking anything (because I’ve definitely messed things up in the past while trying to customize my setup), that would be super helpful! I’d love to hear from anyone who’s managed to do this. What worked for you? Did you follow a specific guide, or was it more of a trial-and-error situation? I’m all ears for any advice or step-by-step guidance you can offer!
How to Change Default Directory in Ubuntu on Windows Terminal
Sounds like you’re having a bit of trouble with the terminal defaulting to your home directory! It can definitely be a pain to have to keep typing `cd path/to/my/project` every time you open it.
Two Main Ways to Fix This
There are mainly two approaches you can take to set up your terminal to open directly in your project folder:
1. Editing the
.bashrc
Filenano ~/.bashrc
and hit Enter. This opens up the.bashrc
file in a simple text editor.CTRL + O
, then hit Enter, and exit withCTRL + X
.source ~/.bashrc
to apply the changes.Now, whenever you open a new terminal, it should jump straight to your project folder!
2. Modifying Windows Terminal Settings
\\wsl$\Ubuntu\home\\path\to\my\project
.This makes it so every time you launch that Ubuntu profile in Windows Terminal, it goes straight to your project directory!
Final Tips
Be careful with the
.bashrc
file, as it can affect how your terminal behaves. If anything feels off, you can always go back and edit it again to remove the line you added. Always back it up before making changes if you’re anxious!Good luck! With any of these methods, you should be good to go without all the extra typing!
To set a default directory when launching Ubuntu through the Windows Terminal, you can modify the Windows Terminal settings directly. Open the settings file by pressing
Ctrl + ,
in the Windows Terminal and navigate to the profile for Ubuntu. Look for the property calledstartingDirectory
and set it to your desired projects folder. For example, if your projects are stored in/home/yourusername/projects
, you would add:"startingDirectory": "//wsl$/Ubuntu/home/yourusername/projects"
. This change will ensure that every time you start a new terminal session, you will begin in your specified directory without the need for additional typing.If you’re interested in making further customizations, you can also utilize the
.bashrc
file in your home directory. To do this, open a terminal and typenano ~/.bashrc
to edit the file. Add the linecd /path/to/your/project
at the end of the file, which will automatically navigate to your projects folder each time a new shell session is initiated. Just be cautious while editing this file; if unsure, you may want to take a backup by copying the original~/.bashrc
file first. Once you’re done editing, don’t forget to runsource ~/.bashrc
to apply the changes immediately. This method is effective and generally safe, provided you’re cautious with the commands you add.