export PATH not saving - bash

I'm trying to install the Google SDK
I type:
export PYTHONPATH=$PYTHONPATH:/Users/morganallen/Dropbox/google_appengine
then:
echo $PATH
And I see:
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/morganallen/Dropbox/google_appengine
But when I quit terminal and re-open it and type echo $PATH I only see:
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Why isn't it saving?
I've seen other answers mentioning a .bashrc file, but I can't find mine? Not sure what to do.

If you type that into the command line, it only applies for the current session (until you close the bash window). Instead, save that line of code into your .bash_profile and it should work for every single session.

A file whose name begins with a period (.) is a hidden file. Depending on the file manager/browser which you may be using, hidden files may not be shown by default. You will need to enable viewing hidden files in the preferences/options as the case may be.
If you are using a command line to list the contents, you can use ls -a instead of plain ls.
And of course, if you need to modify the hidden file using a text editor at the command line itself, (say, using vim/nano etc.) then you can always supply the full name of the file as an argument (including the period).

Related

I have accidentally set up my path environment variable incorrectly using the .bash_profile on macbook. How do I reset it?

-bash: export: /Users/deboadebayo/Desktop/Coding/:/opt/anaconda3/bin:/Library/Frameworks/Python.framework/Versions/3.8/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin':
not a valid identifier
The above message is the error message I receive every time I open my terminal. I did create a backup of my bash profile. But essentially now I can no longer navigate anywhere I want to go using command line requests.
Any help would be much appreciated
If you have a backup, use an absolute path to the mv and cp commands to rename your broken file and restore the backup, both without depending on path lookup.
/bin/mv .bash_profile .bash_profile.broken
/bin/cp .bash_profile.backup .bash_profile
Close the current terminal window and open a new one, which should use your working, original .bash_profile to initialize PATH. Now you try to make the correct modification to your PATH.
oops. The easiest way to fix it would be to launch an editor with an absolute path. $PATH only specifies the locations in which the shell will search if told to execute a program relative (or no) path specified. The which program can search the path and shows the first executable found:
$ which vim
/usr/bin/vim
So if you're a vim user, you should be able to run /usr/bin/vim at the command line, and the path won't be relevant. Then you can fix your file in the editor. Looks like my osx machine also has nano if you'd prefer that editor. I don't think I installed it so it probably came shipped with osx I'm guessing:
$ which nano
/usr/bin/nano
If you want to revert to your backup, use cp, but specify it from its absolute position, /bin/cp:
$ /bin/cp first.txt second.txt
Obviously you'll want to change the file names on that one for it to work for you.

Where are my files saved in vim for windows

I have been using the gvim command :w to save and it works fine saving it to the desktop. However with the vim program, when I use the command :w, I cannot find where the saved file is located.
It should save to whatever directory you started writing it in (you can see that in the command line). You can also use your computer's file search to locate it and then inspect for the file path.
As said by others: by default it saves in the directory where you started it. But if you aren't aware in which directory you started, then a way to find out is to use the :pwdcom in vim. This will output the current directory. That's where vim will store the file.
C:\Users\"windows user"\AppData\Local\Packages\KaliLinux.54290C8133FEE_ey8k8hqnwqnmg\LocalState\rootfs\home\"WSL user"
Adding another answer to get the filename as well.
As mentioned by Cary and Jeen, vim saves your file to the directory from where it is started. You can get the directory where it is saved using :pwd.
If you are interested to get name of the file, it can be done by ctrl + g when your laststatus=1, which is the default value.
I usually set laststatus=2 which always show the filename.

Where do I find out when a pycharm python file was made?

If there is no way to find out is there any way to find out when a file was first created on a Mac?
Mac shows the created time when you select a file in Finder. Almost always editors depend on os provided attributes for this.
There are at least two ways to determine this, and for any file in OSX.
The first option works if you are familiar with Terminal and navigation in Unix (Bash etc on OSX). Use the list files "ls" command.
Navigate to the folder your pycharm python file is contained in. Use the ls command to list the contents of that folder (directory) and include the options t,r and U.
For example:
ls -alhtrU
This instructs the ls command to list:
"a" both visible and invisible files in the directory,
"l" in long (single column down the page) format,
"h" with human readable file sizes,
"t" listed in order of time modified/last accessed/created,
"r" in reverse so most recently created file is at the bottom of the list and hence visible if the list is long as nearest to your command prompt. Finally add the
"U" directing the ls command to use the date the file was
created as the time information for ordering and displaying the
files.
This method is not perfect. If the file was created last calendar year, only the year is displayed. If the file was created this calendar year, the created date and time to the minute is displayed. If you include an r in the ls command as suggested, the most recently created files appear in the ls list at the bottom (reverse order). This is helpful if there are many files in that folder/directory and your files of interest were created recently compared to the other files in that directory.
There is likely a different unix command to show the creation date and time of the particular file your interested in.
Learning the options available for basic Unix commands can be very helpful. This and other options for the ls command can be found by entering in Terminal.
man ls
This gives you the manual page for the ls command. Press "q" to exit when your finished reading to return to the Terminal command line. Or open a second Terminal window to load man pages so that you can reference your options in one terminal window while practicing them in the command line in another.
The second option is to open the folder the file your interested in sits in, in the OSX GUI.
Open the folder, then go to the Finder Menu, under View, select View Options. You can tick the box to show file "Date Created".
This solution saves you the time required to learn more about the ls Unix command and has the benefit of a real time update as you create new files in that folder, which may be desirable. However, as downside, if your interested in invisible files (begin with a "." as shown in ls command in Terminal), then these will not be visible without additional OSX tweaks. An alternative here is using Finder, Find, for that folder specifically and using the more detailed options available in Find.

How do I run a Ruby script created in text editor in the Mac OS Terminal?

I just started reading the Well-Grounded Rubyist, and I am just beginning to use Ruby in my terminal on my Mac.
I'm on the very first lesson, creating a Celsius to Farenheit converter in a text editor. I've saved the code as an .rb file by using Textmate (my text editor). The file name is c2f.rb. The file is saved in a folder on my desktop titled "Rubycode".
I am having difficulty running the .rb file in the terminal however. I've tried many different methods of trying to call the file, including using:
cd /Users/rexrose/Desktop/Rubycode/c2f
and many others.
Any thoughts on what exactly, I'm supposed to type into terminal in order to call the c2f file?
Thanks in advance.
I just started reading Well-Grounded Rubyist.
That's a very good book. I consider it more of an intermediate level book than a beginner book, but no matter.
I've tried many different methods of trying to call the file,
including using
cd /Users/rexrose/Desktop/Rubycode/c2f
The cd command means "change directories" and you cannot change directories to a file. Instead, you have to change directories to the directory containing the file:
$ cd /Users/rexrose/Desktop/Rubycode
Then you can execute your program contained in the file c2f.rb like this:
$ ruby c2f.rb
Here are some Terminal tips:
1) You can use ~ instead of /Users/YourUserName, so you can save some typing by doing this:
$ cd ~/Desktop/Rubycode
Typing '~' instead of '/Users/YourUserName' will become second nature.
2) Using the cd command with no arguments:
$ cd
will take you to your home directory, i.e. /Users/YourUserName
3) You should change your prompt to indicate what directory you are currently in. To do that, create a file called .bash_profile in your home directory(/Users/YourUserName). Check to see if it exists first:
$ cd
$ ls -al
The command ls -al will show all the files in a directory, including hidden files, which are files whose name begins with a .. If a file named .bash_profile exists, open it; if it doesn't exist, create it. Put this in .bash_profile:
PS1="\w$ "
To get Terminal to recognize the changes, you can either Quit Terminal and relaunch it, or do this:
$ source .bash_profile
Then open a new Terminal widow.
You can also add 'aliases' to .bash_profile. For instance, in my .bash_profile I have the alias 'r' for 'ruby', so that I can execute a ruby program like this:
$ r my_program.rb
In .bash_profile you make an alias like this:
alias r="ruby"
4) Tab completion in Terminal:
You might have noticed that you can type part of a file name, then hit tab and Terminal will complete the file name. Using tab completion, I can execute my ruby program like this:
$ r my_pr<tab>
In fact, I name my practice ruby programs so that I can use tab completion to the greatest effect. I have files named 1.rb, 2.rb, 3.rb, and then I execute one of them by simply typing:
$ r 1<tab>
And in fact, you may not even have to type that! If you hit the up arrow key on your keyboard, Terminal will display the previous command, and if you hit the up arrow key again, you will see the command before that. So you can scroll up to a previous command, then hit return to execute it--without having to type anything.
You should endeavor to use tab completion for each of the file names in a path. For example, if you are cd'ing to /Users/YourUserName/dir1/dir2, you should do this:
$ cd /Use<tab>/YourUser<tab>/di<tab>/di<tab>
The reason you should use tab completion for each filename(by the way in Unix filename is a general term for both directory names and file names) is because when the name won't tab complete, then you are in the wrong directory or you are trying a filename that doesn't exist in that directory. So instead of having to type out the whole path '/Users/YourUserName/dir1/dir2' and then finding out about the error when you hit return, the tab completion will let you know immediately when there is an error(because the filename won't tab complete)--saving you some typing.
5) Because you will probably be using Terminal for mostly ruby programs for awhile, you can set up things so that Terminal will automatically open up in your directory Users/rexrose/Desktop/Rubycode. Put this in .bash_profile:
cd "/Users/rexrose/Desktop/Rubycode" (Here you cannot use ~)
6) Occasionally, you may have to type a long file name that exists on your computer into the command line:
$ cd /Library/SomeLongName/AnotherLongName34832o222/142582dir/some_file.txt
Instead of having to type all that at the command line, you can locate the file in Finder first. Then if you drag the file onto the Terminal window, the file name will be entered at the point of the cursor.
Finally, a better way to organize your files might be to put them in directories below your home directory, like this:
~$ mkdir ruby_programs
~$ cd ruby_programs
~/ruby_programs$ mate 1.rb
First things first: cd stands for "Change directory".
Normally the terminal should open in "~", which is the home directory where most of your things are. In OS X it will be /Users/[username]. It's also possible possible that in OS X, it will save the location of the last session. I also recommend, since you're starting to install, "Iterm2", which is a nice terminal to use. It supports multiple tabs, etc.
Ruby, the interpreter, is the command "ruby". To call a script you have to call Ruby with a filename:
ruby /Users/rexrose/Desktop/Rubycode/c2f/c2f.rb
That is almost the equivalent of:
cd /Users/rexrose/Desktop/Rubycode/c2f/
ruby c2f.rb
It's almost equivalent, but for now the difference shouldn't bother you. Let say that the second way to call the script is more favorable than the first.
Now, the second thing: If you want to try things in Ruby, you can start an interactive shell. The command is "irb".
Type irb and Enter and then you can type Ruby code. If you want to leave, press CTRL+C multiple times.
The last thing, I recommend installing "RVM". It will save you time and pain, I hope. If you want to install Ruby gems, it will not mess with the Ruby already present with the system. That's my personal opinion but I believe lots of people will agree. Even if Ruby comes with OS X, you should install a different Ruby for development. It will make sure that if something goes wrong in dev, it will not mess the Ruby OS X might be using.

How to remove entry from $PATH on mac

I was trying to install Sencha Touch SDK tools 2.0.0 but could not run it properly. It created an entry in the $PATH variable.
Later I deleted the sencha sdk tools folder but didn't realize that the path variable is still there.
When i did echo $PATH I got -
/Applications/SenchaSDKTools-2.0.0-beta3:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
I searched on how to remove variables from $PATH and followed these steps :
Gave the command PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin"
Did echo $PATH which showed /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
gave the command export PATH
Closed terminal and reopened it. Gave the command echo $PATH. This time I got
/Applications/SenchaSDKTools-2.0.0-beta3:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
Can anyone tell me what am i doing wrong?
echo $PATH and copy it's value
export PATH=""
export PATH="/path/you/want/to/keep"
Check the following files:
/etc/bashrc
/etc/profile
~/.bashrc
~/.bash_profile
~/.profile
~/.MacOSX/environment.plist
Some of these files may not exist, but they're the most likely ones to contain $PATH definitions.
On MAC OS X Leopard and higher
cd /etc/paths.d
There may be a text file in the above directory that contains the path you are trying to remove.
vim textfile //check and see what is in it when you are done looking type :q
//:q just quits, no saves
If its the one you want to remove do this
rm textfile //remove it, delete it
Here is a link to a site that has more info on it, even though it illustrates 'adding' the path. However, you may gain some insight.
What you're doing is valid for the current session (limited to the terminal that you're working in). You need to persist those changes. Consider adding commands in steps 1-3 above to your ${HOME}/.bashrc.
If you're removing the path for Python 3 specifically, I found it in ~/.zprofile and ~/.zshrc.
$PATH contains data that is referenced from actual files. Ergo, you should find the file containing the reference you want to delete, and then delete said reference.
Here is a good list to run through progressively [copied from #Ansgar's answer with minor updates].
/etc/bashrc
/etc/profile
~/.bashrc
~/.bash_profile
~/.profile
~/.MacOSX/environment.plist
/etc/paths
/etc/paths.d/
Note that /etc/paths.d/ is a directory that contains files with path references. For example, inside this directory may be a file called, say, fancy-app, and inside this file you'll see an entry like below:
/path/to/fancy-app
This path will appear in your $PATH and you can delete the entry in the file to remove it, or you can delete the file if it has only the one reference you want to remove.
Use sudo pico /etc/paths inside the terminal window and change the entries to the one you want to remove, then open a new terminal session.
when you login, or start a bash shell, environment variables are loaded/configured according to .bashrc, or .bash_profile. Whatever export you are doing, it's valid only for current session. so export PATH=/Applications/SenchaSDKTools-2.0.0-beta3:$PATH this command is getting executed each time you are opening a shell, you can override it, but again that's for the current session only. edit the .bashrc file to suite your need. If it's saying permission denied, perhaps the file is write-protected, a link to some other file (many organisations keep a master .bashrc file and gives each user a link of it to their home dir, you can copy the file instead of link and the start adding content to it)
Close the terminal(End the current session). Open it again.
If the manual export $PATH method does not seem to be working after you close the terminal and open again, definitely check the shell configuration files.
I found a small script that kept adding some more path in front of the $PATH everytime it was open.
For zsh you can check the ~/.zshrc file.

Resources