How can we know the default Installation Directory of XCode through command line?
Asked Answered
O

2

14

Is there a way to know the Default Installation Directory of XCode through command line? (I know default is /Developer, but what if i changed it to /XCode42, then in this case how can i get path)

Also where is those environment variables are set and what are the names for those variables? (As in windows we are giving Path for Java)

Oppugn answered 9/11, 2011 at 7:0 Comment(0)
P
42

This will do

xcode-select --print-path
Probability answered 10/11, 2011 at 13:18 Comment(0)
S
1

if your xcode direcotry is in the path you can use the command which:

 # which Xcode

this will return the path to the executable (only if it can be found using the PATH environment variable).

to find the enviroment variables open the shell and type (if you are using the bash shell):

 # env

this will display the environment variables.

if you have the Xcode running you can run a ps command and grep the path from the output:

# ps -e -o command | grep Xcode | cut -d" " -f 1 | grep -e "Xcode$"

this will return you the path of the running Xcode (tested on my mac).

You can add your Xcode bin directory to your PATH by editing your .bashrc file and adding this line:

export PATH=$PATH:/Developer/Applications/Xcode.app/Contents/MacOS/

then do a

# source .bashrc

and then you can execute your Xcode form the command line by directly typing Xcode and the which command will return you the path to the Xcode.

Seiler answered 9/11, 2011 at 11:49 Comment(5)
But running which command does not give me any output in Mac OS Lion Terminal. And when I run env it shows environment variables but not of XCode. So where does actually XCode saves the /Developer or other installed directory path??Oppugn
I have 2 XCode installed, one at /Developer and other at /Developer40 path... But still which command does not show any output. Can you please tell me how to use which command? I am using it like which Xcode. Is this OK?Oppugn
which syntax is which executable_name . which command will return no output if your Xcode is not on the PATH. So if none of the /Developer or /Developer40 is on the PATH (and this looks like your case) you will get no output. I have edited my answer adding info on how to get the Xcode path if your Xcode is running. You can also use the find command to get all the files named Xcode in your system but this one will return both paths.Seiler
ok so you mean that i need to keep xcode running while using this command. But my case is different. ps command will take the process that are running. I want that i should get path of Xcode from another program without opening xcode.Oppugn
ok, then this is a different story, but you want to take which of the two Xcode? For this the best thing to do is to change your .bashrc and add the path to the desired Xcode to your PATH variable (then your which command will run too).Seiler

© 2022 - 2024 — McMap. All rights reserved.